Switching Your GitHub Repo To Use Only The gh-pages Branch

Last updated:

(This is a simplified version of the advice on Oli Studholme's blog, cut down to just the parts that I've actually needed. I do this often enough, and always forget the steps, so having it put down here is useful for me, and maybe for someone else.)

So you want to serve your repo from the http://user.github.io/repo url, and don't have any reason to separate a "code" and "serve" branch. In other words, you want your GitHub repo to only use the gh-pages branch, not master. Here's an easy guide to making that happen.

First, if you already have a gh-pages branch, make sure it's synced up to master, showing exactly what you want. If you don't, type:

git checkout -b gh-pages
git push origin gh-pages

Second, go to GitHub, settings for your repo, and switch “Default Branch” to gh-pages.

Third, switch to your gh-pages branch, and delete the local master branch with git branch -d master.

Finally, delete the remote master branch with git push origin :master.

Done. You now have only the gh-pages branch, and it's the default one that git will use when talking with GitHub.

(a limited set of Markdown is supported)

#1 - mike lewis:

thanks for these instructions... one tweak.... may want to mention that user should be on branch 'gh-pages' and not 'master' when run 'git branch -d master'. i tried to run that command from master branch and kept getting the 'error: Cannot delete the branch 'old_branch' which you are currently on.' once i switched to gh-pages and then ran 'git branch -d master' & 'git push origin :master' it worked

Reply?

(a limited set of Markdown is supported)