Deploying your JS App to Github Pages the easy way (or not)
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-pages
branch 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 git
commands, one can simplify the deployment process. Wouldn’t it be nice to just go into dist
folder, 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