Deploying your JS App to Github Pages the easy way (or not)

Christophe Hamerling
2 min readSep 25, 2018

The Github Pages solution to deploy you static application and have it online on https://YOU.github.io/YOUR_REPO_NAME is something quite easy to setup and widely used: By default, you push something on gh-pagesbranch and 💥, it is available on a Web page.

It can be even more powerful if you can just get rid of having checkout branch yourself, remove useless files, commit only the required files, etc…

Since most JS frameworks builds comes by default to the dist/folder and by using the right gitcommands, one can simplify the deployment process. Wouldn’t it be nice to just go into distfolder, push changes and have your remote site updated without all the junk around? This is what can be achieved by using git worktree.

All the commands below assume that you already have a git project initialized and that you are in its root folder.

# Create an orphan branch named gh-pages
git checkout --orphan gh-pages
# Remove all files from staging
git rm -rf .
# Create an empty commit so that you will be able to push on the branch next
git commit --allow-empty -m "Init empty branch"
# Push the branch
git push origin gh-pages

Now that the branch is created and pushed to origin, let’s configure the worktree correctly:

# Come back to mastergit checkout master

--

--

Christophe Hamerling

Staff Software Engineer at @Doctolib, leading French healthcare platform. Building tools and libraries that make developers' lives easier and more productive