Skip to content

Instantly share code, notes, and snippets.

@benklocek
Last active December 16, 2015 22:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benklocek/5505392 to your computer and use it in GitHub Desktop.
Save benklocek/5505392 to your computer and use it in GitHub Desktop.
Git Hub repo post-update hook to update based on branch pushed. modified from http://blog.ekynoxe.com/2011/10/22/git-post-receive-for-multiple-remote-branches-and-work-trees/
#!/bin/bash
#
# post-update hook for Hub git repo
# http://stackoverflow.com/questions/5753346/git-automatically-push-to-dev-and-production-from-central-repository-depending-o?rq=1
# post-update only receives refname
# TODO: adjust for post-update ref, and cd to Prime and pull
#
livepath="/path/to/your/live"
devpath="/path/to/your/dev"
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [[ "master" == "$branch" ]]; then
git --work-tree=$livepath checkout -f $branch
echo 'Changes pushed live.'
elif [[ "development" == "$branch" ]]; then
git --work-tree=$devpath checkout -f $branch
echo 'Changes pushed to dev.'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment