Remove and ignore all files that have an extension from a git repository Remove and ignore all files that have an extension from a git repository python python

Remove and ignore all files that have an extension from a git repository


Plenty of ways to remove them:

git ls-files | grep '\.pwc$' | xargs git rmfind . -name *.pwc | xargs git rm

Note: If you haven't committed them, just use rm, not git rm.

To ignore them in the future, simply add *.pwc to the .gitignore. (If you don't have one, create a file named .gitignore at the top level of your repository, and just add a single line saying "*.pwc")


You can also use the following:

git rm -r '*.pwc' 

and then make those files ignored by git:

echo '*.pwc' >> .gitignore

The last one is in case if you already have .gitignore file, if not, us single '>' sign.


In Windows this worked for me:

git rm -r '*.pwc' -f

And for keeping it in .gitignore

echo '*.pwc' >> .gitignore