If you’re amateur enough, not to feel uncomfortable after pushing those files, you’re golden. Else, you’ll think of something called .gitignore which helps in ignoring unwanted files to be added in your git repository.

You’ll then search for a good gitignore file for Python and Google will give you exactly what you want, Python.gitignore.

Now, you’ll try to remove the pyc files, using rm -rf *.pyc. But as soon as you’ll do this, (and if you’re using oh-my-zsh), you’ll see a cross on your prompt. That means, git has detected a change.

But wait? Why is git detecting changes to pyc files, when I’ve already added the gitignore!

Now, if you’re me, you’ll feel betrayed by git. You’ll make a few calls and send messages to people, and say “gitignore is not obeying me”, and they’ll hang up on you, saying “it must be your fault”.

Believe me, even the “future me” would have said the same.

So, the problem is that once you have staged a file, gitignore won’t have anything to do with it. So, if you’ll remove the staged file (pyc files, in this case), git will say to you that you’ve deleted them.

Later on, I googled the string “gitignore not working” and O thanks to stackoverflow, I was rescued.

After adding the .gitignore, simply do this

git rm -rf --cached .
git add .

Or, instead of rm -rf *.pyc

, I must have done

git rm -rf *.pyc

Ta-da ! And that’s when, my friends, the trust I have in git’s simplicity increased by a tini-tiny bit.

Thank you for reading.

When a python script is compiled, it generates compiled code as pyc files, also called byte code.