Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use git worktree to maintain GitHub Pages branch
# Initialize a gh-pages branch... GitHub expects this branch to exist to publish a project website from it.
git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty -m "Initializing gh-pages branch"
git push origin gh-pages
git checkout master
# Define a directory where the static website files will reside
# Add a working tree for the new gh-pages branch (this allows us to work on the website without checking out that branch)
git worktree add -B gh-pages $WEBSITE_DIR origin/gh-pages
# TODO build the website into the WEBSITE_DIR directory
# Publish the just-built website files
cd $WEBSITE_DIR && git add --all && git commit -m "Publishing to gh-pages" && cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment