Enter your email below to get insights on starting, running and growing a creative company

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-2018 James Chambers
Learn from my mistakes

Sign up to my mailing list to get insights about starting, running and growing a creative company.