Skip to content

Instantly share code, notes, and snippets.

@dsferruzza
Last active August 29, 2015 14:14
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 dsferruzza/a29e46123423dc46f57e to your computer and use it in GitHub Desktop.
Save dsferruzza/a29e46123423dc46f57e to your computer and use it in GitHub Desktop.
Git hook to keep gh-pages branch up to date with master
# This needs to be executed once to create the "gh-pages" branch
git checkout --orphan gh-pages
git rm -rf .
# This is the part to adapt
FILE="site/index.html"
git checkout master -- $FILE
git mv $FILE index.html
git commit -am "First commit"
git checkout master
#!/bin/sh
# .git/hooks/post-commit
# Check if the commit is done on master branch
if [ $(git rev-parse --abbrev-ref HEAD) = "master" ]; then
git checkout gh-pages
# Get new content from master to gh-pages
# This is the part to adapt
FILE="site/index.html"
git checkout master -- $FILE
git reset HEAD $FILE # Remove file from stage
mv $FILE index.html
git commit -am "Get content from master branch"
git checkout master
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment