.git/hooks/post-checkout

#!/bin/bash find $(git rev-parse --show-cdup) -name "*.pyc" -delete

Recently, I've found myself increasingly caught out by stale .pyc files in our project. When I change from our mainline branch to a story branch (or vice-versa), I often find myself with inexplicable test failures because Python is using the .pyc files for no-longer-current code.Luckily, it's pretty easy to fix this in git, using hooks , specifically the post-checkout hook. To do that, add the following to, and make the file executable:Now, every time you checkout a new branch, all the .pyc files will be cleared out of your git branch.