How to remove files that are in gitignore but still in the git repository
I searched up for this command so much I just wanted to have it as my under the toolbelt.
August 05, 2022 • Code
There are numerous times where we either forgot to remove some unnecessary files but are commited and pushed to master branch in GitHub. In these situation, the following code which I found in StackOverflow helped removing the files from the master branch:
git rm --cached `git ls-files -i --exclude-from=.gitignore`
If you are on windows, you can try:
git ls-files -i -z --exclude-from=.gitignore | xargs -0 git rm --cached
One thing I think is important is to update the .gitignore file before running the code in order to properly work.