Last active
August 29, 2015 14:14
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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