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:

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


  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!

    1. 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 Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s