Deploy a subfolder as a GitHub pages site

August 2017

Static sites on github must be deployed to the gh-pages branch. Sometimes you may want to deploy a sub folder within your repository to be at the root of your site. For example:

-- / 
---- build/ << contains built site
---- source/
---- etc..

You can deploy the /build/ folder from the master branch to the root of gh-pages using the subtree command:

git subtree push --prefix build origin gh-pages

As a bonus, if you're using a custom domain you need to ensure there's a CNAME file in the root of the /build/ folder with the domain name in it. You can wrap this up in a shell command like so:

touch build/CNAME
echo \"\" >> build/CNAME

Ever wish you got more email?

Neither do I. You're busy, and so is your inbox. I'll only be in touch when I publish something new. And of course it goes without saying your email will be kept completely private.