Web-Hosting a Github Repo

If you’ve got a project on github that you’d like to web-host at username.github.com/project (that is, it has an index.html in the project root, perhaps documenting or demonstrating the project, or which is the project), the procedure is much simpler than the procedure for setting up GitHub Pages branch with entirely separate content from the source.

Starting with a clean repo (nothing pending):

0. If you’ve already checked the “GitHub Pages” box on the project’s Admin page, get rid of the gh-pages branch that has been automatically created like so:

$ git checkout gh-pages      # pull in the gh-pages branch
$ git checkout master        # back to the master branch
$ git branch -d gh-pages     # delete the default content
$ git push origin :gh-pages  # also remove it from the server

1. Otherwise, it’s as simple as creating a branch called gh-pages:

$ git branch gh-pages        # now gh-pages is just a clone of the master
$ git push origin gh-pages   # put it up on username.github.com/project

2+. Now each time you want to update the GitHub Pages page with new stuff in the master branch:

$ git checkout gh-pages
$ git merge master
$ git checkout master
$ git push

Leave a Comment