So here\'s an interesting situation when using git and python, and I\'m sure it happens for other situations as well.
Let\'s say I make a git repo with a folder /foo
Just copying and updating a good solution by Apreche that was buried in the comments:
Save this shell script to the file /path/to/repo/.git/hooks/post-checkout, and make it executable.
#! /bin/sh
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
find . -name "*.pyc" -delete
find . -type d -empty -delete