Sometimes you want to commit a subfolder on an arbitrary branch (rather than gh-pages branch) as the root directory
to the gh-pages branch.
You will want to do so when, for example, the files to be published on GitHub Pages are generated by a build system.
This document shows the way to commit a build/gh-pages directory to the gh-pages branch by using Git plumbing commands.
In the following example, Windows PowerShell is used as a shell environment.
git add -f ./build/gh-pages
$treeObjId = git write-tree --prefix=build/gh-pages
git reset -- ./build/gh-pages
At first, create the Git tree object by using git write-tree command.
To create a tree object that represents a subdirectory, use --prefix option.
$commitId = git commit-tree -p gh-pages -m "YOUR COMMIT MESSAGE" $treeObjId
Next, you need to create a new commit by using git commit-tree command.
Its parent is a commit which is referred by gh-pages branch, and its tree object is the created one at step 1.
git update-ref refs/heads/gh-pages $commitId
Last, make gh-pages branch refer to the created commit at step 2 by using git update-ref command.
- GifWirter.js project's
:demo:websubproject has actual example on Gradle build script.
- Deploying a subfolder to GitHub Pages : This shows the way to push the committed subdirectory on the
masterbranch to remotegh-pagesbranch by usinggit subtree pushcommand.- You need to commit the built files on the
masterbranch (or arbitrary branch other than thegh-pagesbranch) to deploy GitHub Pages.
- You need to commit the built files on the
Thank you! This worked great! 💯
If one needs to (like I did), the PowerShell syntax for variable assignments can be adapted to Bash and similar like this:
treeObjId = $(git write-tree --prefix=build/gh-pages)