/var/log

Github gh-pages and master

I often create a gh-pages branch for my Github projects as a simple website for the master branch. These are the commands to keep gh-pages up to date with the master branch and push everything to the remote:

# In master:
git add .
git commit -m "A commit"
git push origin master
git checkout gh-pages

# Now you're in gh-pages
git merge master
git push origin gh-pages

Another common scenario is to push a subdirectory of the master branch to the gh-pages branch, for example to show the built project or documentation. To do this is very easy. For example if we want to show the docs directory of the master branch to be the root directory of the gh-pages branch:

git subtree push --prefix docs origin gh-pages

This will create the gh-pages branch if it didn't exist, so no need to locally create and manage this gh-pages branch. If you get a rejected, you can do (optionally with a --force flag):

git push origin `git subtree split --prefix docs master`:gh-pages
Tag: , | Category: