Hosting your git repositories - part 2

Published: 2024-12-23

This article will discuss giving public read access to your git repositories, for setting up private write permission see part 1.

Using the git dumb protocol

This is the easiest way in my opinion to let your git repo be cloned or pulled. The advantage of this protocol is that your repo can be fetched using HTTP, the git program knows how to clone a repo using HTTP and will use it automatically if needed.

This means you can serve your repository using any HTTP server, i.e. apache, caddy, tomcat etc, since your git files are just static files. There are drawbacks of course, this protocol is slow and old and has been replaced by the smart protocol, which unfortunatelly doesn't work with normal HTTP servers.

To start using this technique, configure your HTTP server to serve static files from a folder, say repos. Inside that folder you can create your bare repositories, i.e. proj1 with:

cd repos && git init --bare proj1

This will create a new (empty) repository. You can also make a bare clone of an existing repository using:

cd repos && git clone --bare [your repo url]

However, you will notice that these repos cannot be accessed by HTTP, that's because the repo is lacking some auxiliary files needed.

update-server-info

This command is used to generate or update the necessary files for a dumb server be able to serve the repo properly, you must manually run this at the time you create your bare repos:

cd proj1 && git update-server-info

Now you should be able to clone or pull from this repo. Now, to run this automatically every time you push to your repo you can use the git hook strategy, so you always serve updated content.

Using git hooks

Git hooks are your friend and they have even more use for dumb servers, to run update-server-info for every push I chose the hook post-update, which runs after the new commits are added, the sample that comes is good enought for my distro. If not just add the command there and rename the hook without the .sample suffix.

This is the way I configured my project lin0. But there are still improvements for this setup. To be able to serve the files from the repo I also added: git --work-tree=tree checkout -f main which is the index page you see. In the future I will move this to remove the tree path.

Other options

This short article showed the dumb server approach, but there are many others, some I'll probably publish in follow ups. Some options are: There are much more, but these are some good starting points. Each has its own pros and cons, in the next article we will discuss some of them, for me what is working better is this dumb protocol and git hooks combination, but this is a matter of personal taste and requirements. Thanks.