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/stagitand run make
- Install the binary to a location in your
- Create a top level directory to hold the stagit copy of the repos. This is called
- Copy the
*.pngfiles from the stagit repository to
reposdiror use your own.
- Copy the
post-receivescript somewhere outside the
stagit-filesrepo so that it can be customized.
- Edit the
reposdirto the directory you created to hold the repos.
post_receiveto the path of the copy of the script.
- Edit the copy of the
- Set BASEURL to where you are serving the git repos from
RSYNC_DESTif you want to use the
rsyncat the end of the file to copy them over
reposdirto match the
- 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.
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.
setup-stagit-script only supports
main branches, if you
have named the
master branch something else edit the script and add it to the
case that currently only matches
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
your git config for this repo.
You can now run
git push stagit master and it will push to the
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.