The one where we talk about bare git

Earlier this year I read a blog post by @technomancy about his transition from GitHub to other code hosting platforms and how to split up the monolith that is code hosting, issue tracking, CI and authorization. The topic strongly resonated with me as I too shifted off GitHub nearly a decade ago and then off GitLab a few years after that.

What stuck with me the most was the blog’s opening, where he laments the mindshare dedicated to thinking of shared code repositories only through the lens of GitHub’s forge model. When you walk through air you don’t realize its all around you. When all you’ve known is the forge model you don’t stop to think about what it is or why it is.

While a forge offers you a buffet of tools beyond just storing code, you likely will not need all of them (or any of them for small projects). Those tools you do need can be integrated in other ways, independent of a forge.

What a forge truly offers that cannot be found elsewhere is free hosting and a network effect. Free hosting comes with a cost, either the implicit cost where you recognize that your code is being used to feed LLMs or the time cost of getting caught in the cross fire of escalating bot countermeasures. The network effect rapidly turns against you as people seek alternative forges. Now in order to use the pull request model you’ll need accounts on multiple forges (I maintain accounts on GitHub, GitLab AND CodeBerg).

Escaping the Forge

If all you need is a place to store your code, you want that code to be publicly available, and you don’t expect a significant volume of contributions, spinning up a VPS to hold bare git repositories and statically rendering them as html behind a reverse proxy is trivial (read as less than 2hrs of work). The rest of this post will focus on the steps involved in getting your own public git remote working (sans forge), and the resources I used to setup mine.

Git itself can operate over ssh. Having a remote repository is as simple as creating a bare git repo on a publicly available remote machine and adding your client machine’s public key to the remote machine’s list of authorized keys. Details on how to do this are covered directly in the git book. If you already have a VPS you can get up and running in under 5 min (including the extra steps to harden your remote server)!! For private remotes that you don’t want to render publicly you can stop here.

If you’d like your code to be visible to the public there are numerous libraries that render your git repo as HTML. The most popular tool for rendering git as html is probably cgit. The name accurately describes the project, being a portmanteau of c (the language its written in), cgi (how it interfaces with your git repo), and git. Alternatively you can use one of the many static front ends. While these do not offer the same level of interactivity as a cgi powered tool like cgit, they are resource-lite and trivial to customize.

I ended up using the static git front end legit, pronounced according to its author as a frenchman saying “Oui, il est le git”. If you have go installed on your system, getting started is as easy editing the config.yaml, pointing your reverse proxy to the port you specify in the config, and running git build && ./legit. This process took me about a half hour, which included creating a sub domain for my website and setting up TLS certs for my reverse proxy. I spent several hours after this modifying legit to suit my needs, but I consider that as extracurricular.

At this point you’re able to interact with your remote repo over ssh like any other remote and the public can see the code you’re working on. What’s missing is the ability for the public to clone the repository so they can fiddle with it themselves. Git has an http backend that supports interacting with the repo over http directly. Getting it working behind a reverse proxy to get https support is a bit tricky.

ESC.sh has a post walking through setting up the process with NGINX. The post is helpful for setting up a Debian based system with the required dependencies. However, their NGINX config is focused on using https as a means of authorizing pushing to the repo not just anonymously cloning it. Kreijstal provides a comprehensive guide that covers both the material on setting up an ssh remote server from the git book and also setting up your NGINX server to only permit anonymous cloning. For me, getting anonymous cloning working was the longest part of this project, taking me about an hour of researching, troubleshooting and investigating how fastcgi works with NGINX.

So, how’s it going?

For the past week I’ve been storing my personal repos on my own server. The page load time is phenomenal compared to CodeBerg, GitLab or even SourceHut. ~120 ms for a first time page load, and less than 50 ms (with latency) for subsequent loads. These load times let you navigate your code tree at near native speeds. I have found myself on more than one occasion hard refreshing a page by accident because it loaded so quick I thought it was a locally cached page.

I don’t expect to receive change requests for these repos, they are my truly personal projects. Like my custom fork of legit and my advent of code answers. I will continue to use CodeBerg for larger projects, which I anticipate receiving issues and change requests for.

In sum, if you’ve got a couple hours lying around one weekend and you have a VPS or a publicly available machine try setting up your own git remote. Just try not to fall down the rabbit hole of web customization.

PS - make sure you have some sort of backups for your remote machine.

PPS - for “Pull Requests” you can always receive patches via email. I should probably setup an email address specifically for this. Alternatively, if they host their own site, they can point you to the branch with their recommended page that you can clone from them!!! No auth required.