Git — Remove all .pyc

To remove all your .pyc files from your git repo…

First, git rm them
find . -name "*.pyc" -exec git rm -f {} \;

Then, add a .gitignore file in the root of your repo and enter a line:
*.pyc

to prevent them from being added automagically in the future without an -f

16 Comments

  1. very useful for git newbies (like me). one addition i would make is to change “*pyc” to “*.pyc”, otherwise you may accidentally wipe out files that end in pyc as well (rather than files with the extension pyc) – unlikely but possible!

  2. siddharth says:

    thanks…really helped

  3. reposted and linked back to your blog. Hope that’s ok. Really helpful!!!

    http://davidreynon.com/git-mass-delete-by-find/

    1. Yuji says:

      Hey David,

      Thanks for the link back! Awesome 🙂

    2. Yuji says:

      I’ve been using the following more often recently as I can never remember the -exec syntax.

      find -name “*.pyc” | xargs git rm

Leave a reply to olympicfoodtrucks Cancel reply