Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created May 4, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpetto/3ed009c097ea0e45fb59a5f9ee10d7ed to your computer and use it in GitHub Desktop.
Save jpetto/3ed009c097ea0e45fb59a5f9ee10d7ed to your computer and use it in GitHub Desktop.
Git post checkout hook for Python projects
#!/usr/bin/env python
import sys, os, re
from subprocess import check_output
prev_head = sys.argv[1]
new_head = sys.argv[2]
is_branch_checkout = sys.argv[3]
if is_branch_checkout == "0":
print "post-checkout: This is a file checkout. No .pyc files to remove."
sys.exit(0)
print ""
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "~ post-checkout: Deleting all .pyc files... ~"
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print ""
for root, dirs, files in os.walk('.'):
for filename in files:
ext = os.path.splitext(filename)[1]
if ext == '.pyc':
os.unlink(os.path.join(root, filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment