Static git hosting with stagit

I like hosting my own services when possible. But I don’t like maintaining complex systems, so instead of setting up my own GitLab, Gitea, or Gogs service I decided to follow the same path I took with this blog and host some of my git repos as static html pages using stagit .

One of the neat features of git is that you can actually clone from one of these static repos so they aren’t just html pages but are full copies of the git repo, complete with history.

To help with this I wrote a simple script to setup a new stagit remote target and modified the post-receive example distributed with stagit. You can find the files and the README here in my stagit-scripts project .

Self hosting git repositories as static html pages

The stagit project generates static html pages for your git repositories. You can even set it up as a remote so that pushing to it will update the pages and copy them to wherever you are hosting your domain.

  • Check out git://git.codemadness.org/stagit and run make
  • Install the binary to a location in your $PATH
  • Create a top level directory to hold the stagit copy of the repos. This is called reposdir in setup-stagit-remote.
  • Copy the *.png files from the stagit repository to reposdir or use your own.
  • Copy the post-receive script somewhere outside the stagit-files repo so that it can be customized.
  • Edit the setup-stagit-remote script:
    • set reposdir to the directory you created to hold the repos.
    • set post_receive to the path of the copy of the script.
  • Edit the copy of the post-receive script:
    • Set BASEURL to where you are serving the git repos from
    • RSYNC_DEST if you want to use the rsync at the end of the file to copy them over
    • reposdir to match the reposdir from setup-stagit-remote
    • Check the rsync at the end of the script and replace with your own upload method if needed.

WARNING Do not put sensitive information in the post-receive script, it is uploaded to the html server as part of the git repository and is exposed to the world.

The reposdir should not be the same directory as your normal repos. It will contain bare clones of them and only be used to build the html pages and upload them to your html server. Multiple repos will be under this directory, with an index.html file pointing to them.

The setup-stagit-script only supports master and main branches, if you have named the master branch something else edit the script and add it to the case that currently only matches origin/main.

Setup a new repo

cd to the working directory of one of your repos and check out the primary branch. Then run setup-stagit-remote. It will prompt you to enter a description of the project, which will be displayed on the html pages. It will then make a bare clone of the repo and add a new remote, named stagit, to your git config for this repo.

You can now run git push stagit master and it will push to the $reposdir repo, run stagit on it, and upload it to your html server.

Now you can visit your webpage, and test cloning one of the repos to make sure everything is working.