Using a static site generator with Codeberg pages

I had a set of small sites with various build processes I wanted to port from GitHub Pages to Codeberg pages, and wanted a simple way to publish content to a branch. I didn’t want to have to use or learn a new CI system, so instead settled on adding some commands to a Justfile.

Create an empty pages branch to host the content:

git switch --orphan pages
git commit --allow-empty --message "initial commit"
git switch -

Configure dist/ (or the directory the build process outputs to) as a worktree with the pages branch.

git worktree add dist pages --no-checkout

Run the static site generator or build, outputting files to the dist/ directory.

Enter the dist/ directory—git commands will now operator on the pages branch—and commit and push the built files. You can run this every time the source changes.

cd dist
git add --all
git commit --message "dist"
git push

All done!

When working from a fresh git checkout, the worktree will need to be configured first:

git switch pages
git switch -
git worktree add dist pages --no-checkout