Your self hosted git server in less than two minutes

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. - Antoine de Saint-Exupéry

The superior UX of plain text

I might be starting to turn into the Grug Brained Dev, but ever since I start using Vim circa 2019, I swear by plain text. I find the “ownership” and user experience of text interfaces often superior to their GUI counterparts. Not always, but very often, especially for most software development related tasks.

They are predictable, reliable and easy to manipulate.

Discovering email-based version control

As I’m going deeper in the Emacs, Guix and Linux rabbit hole, I started lurking on mailing lists more and more. In those projects, version control (git, in most cases) is often handled entirely via emails.

I don’t know how I haven’t heard about this by now. It’s not something you see in the web world much at all.

As a huge fan of text interfaces, this is very appealing. Importantly, it also mean that you own the entire version control data, since it leaves in your mailbox instead of a third-party database.

Git’s built in SSH protocol

The other day, I was chatting with a friend regarding this subject and my self-hosted Forgejo instance. I mentioned that while it’s an awesome piece of software, I don’t really need it.

I said something along the lines of “It’s really nice, but really, I only just need a simple git server; I don’t really need a GUI. Maybe I should migrate to sourcehut.”/

That’s when he sent me the link to this video of Tsoding about git’s server protocols.

Git has a multiple server protocols built-in, including SSH. In essence, instead of hosting an entire forge, you can simply push and pull from a server via SSH. The git ‘server’ is simply your file system and SSH for transport.

It removes complexity by eliminating another moving part. One less thing to maintain, update and secure.

It give everything I need, and nothing I do not need. Perfect.

A git server in less than two minutes

Set up the server

First, you need to initialise an empty repository on the server.

We use `–bare` as we don’t need a the source, we only need the `.git` folder.

`ssh user@hostname ‘git init –bare /path/to/my/repo.git’`

Set up the client

If you have a current origin, remove it with `git remote remove origin`

Then add your server as the remote: `git remote add origin ssh://user@hostname/path/to/my/repo.git`

The first time you push to the new origin, you might need to set the upstream `git push –set-upstream origin my-branch`

You can now push and pull to your server. And that’s it. Literally.

This is simplicity at its best and I love it.

Note: Don’t forget to backup the repository in case something happens to your server; I personally use restic and keep a copy off site.