Skip to content

Instantly share code, notes, and snippets.

@thiagoghisi
Created July 24, 2014 20:22
Show Gist options
  • Save thiagoghisi/e87a3a03dca417a59780 to your computer and use it in GitHub Desktop.
Save thiagoghisi/e87a3a03dca417a59780 to your computer and use it in GitHub Desktop.
Post-checkout git hook (django project example - step-by-step)
thiago@d:~/we-b-ackend (master)$ vim /home/thiago/we-b-ackend/.git/hooks/post-checkout
thiago@d:~/we-b-ackend (master)$ cat /home/thiago/we-b-ackend/.git/hooks/post-checkout
#!/bin/bash
set -e
printf '\npost-checkout hook\n'
# Delete .pyc files and empty directories from root of project
cd ./$(git rev-parse --show-cdup)
# Clean-up
find . -name ".DS_Store" -delete
NUM_PYC_FILES=$( find . -name "*.pyc" | wc -l | tr -d ' ' )
if [ $NUM_PYC_FILES -gt 0 ]; then
find . -name "*.pyc" -delete
printf "\e[00;31mDeleted $NUM_PYC_FILES .pyc files\e[00m\n"
fi
thiago@d:~/we-b-ackend (master)$ chmod u+x /home/thiago/we-b-ackend/.git/hooks/post-checkout
thiago@d:~/we-b-ackend (master)$ git co MAR-429
Branch MAR-429 set up to track remote branch MAR-429 from origin.
Switched to a new branch 'MAR-429'
post-checkout hook
Deleted 255 .pyc files
thiago@d:~/we-b-ackend (MAR-429)$ git co master
Switched to branch 'master'
post-checkout hook
thiago@d:~/we-b-ackend (master)$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment