Let's stay in touch
Get one email every month or so about software products, marketing, and entrepreneurship

Deploy a subfolder as a GitHub pages site

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/
---- README.md
---- 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 \"domainname.co\" >> build/CNAME
Posted August 2017
© 2014-2019 James Chambers
Discover the tools behind great software products

Sign up to The Inner Joiner, my weekly newsletter about the tools and techniques behind great software products.