Skip to content

Instantly share code, notes, and snippets.

@kleinschmidt
Last active August 29, 2015 14:15
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 kleinschmidt/72dfaa9e0c87bf68724c to your computer and use it in GitHub Desktop.
Save kleinschmidt/72dfaa9e0c87bf68724c to your computer and use it in GitHub Desktop.
A pre-push hook to automatically publish to github pages every time you push.
#!/bin/bash
# drop this in .git/hooks/, and chmod +x .git/hooks/pre-push
# store current branch
cur_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $cur_branch == "gh-pages" ]]
then
# bail out if we're trying to push the gh-pages branch (to prevent infinite loop)
exit 0
else
# merge current branch into gh-pages
git checkout gh-pages
git merge -m 'automatic pre-push merge' $cur_branch
# push gh-pages
git push origin gh-pages
# switch back and exit
git checkout $cur_branch
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment