Autopush to ghpages

2016-07-31

Github pages are nice but there's no way to have it just mirror the master branch, you must push updates to gh-pages branch.

Luckily git allows you to setup repos such that you push to two branches at once. Unfortunately you'd have to set that up for every computer but you can copy/paste most of it.

By default, a fresh repo's /.git/config looks like this:

Code:
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:USER/PROJECT.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master

You'll want to change it to something like this:

Code:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:USER/PROJECT.git
fetch = +refs/heads/*:refs/remotes/origin/*
push = refs/heads/master:refs/heads/gh-pages
push = refs/heads/master:refs/heads/master
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "gh-pages"]
remote = origin
merge = refs/heads/gh-pages

Now when you push to master it will automatically also push to gh-pages.

There may be some catches and I can't explain them to you. I only use this for simple project repos myself.