This little project was as brilliant as it was simple. I own a number of Raspberry Pis, a couple of 1B, 3B and Zero W. I did get a standard Zero variant from Microsoft on a conference, as they handed them out in conjunction with an initiative for Azure.

I am really addicted to these small things, and always have to constrain myself from buying more. Especially since I’ve not really managed to do something productive with them lately. Historically, I have however managed my own ownCloud instance on a first generation Raspberry Pi (this was before Nextcloud existed). This worked fine, but I am too paranoid to run my own server.

Anyway, in conjunction with me creating a website that collects information from a number house brokers as me and my family are looking for a new home, I started one of my spare Zero W. This website is running 24/7 and is not exposed on the Internet. My paranoia is at rest.

Looking for some inspiration of more services to run on this Pi, I made some quick spur of the moment duckduckgoin. And there it was, great tutorial for a very useful project - a git server! My needs are very minimal, as I only want a centralized place that my computers can reach from home. This scratches the itch I’ve had with some projects that I’ve made that I don’t want to be public (e.g. a script that publishes this site automatically on my web host).

I followed this tutorial, but located the repository folders on a USB stick instead. My thinking is that the stick could be more reliable and durable than the SD card.

But anyways, here is the gist of it. First, we add a dedicated user. You could use a “normal” account instead, but I really believe in each service/function shall have as limited permissions as possible.

sudo useradd git

Then we create a dedicated group. This will be used when setting folder and file permissions.

sudo groupadd git

I edited the fstab file to automount the USB stick. I initially formatted it as FAT, but quickly found out that it is not possible to change the ownership of the folders and files. Formatting it as ext4 fixed this.

sudoedit fstab

I do not claim to be an expert in how the fstab works, so I refer you to the manual.

I created the mount point that I wanted and made the created git group and user owner of it.

sudo mkdir /data
sudo chown -R git:git /data

I then configured the SSH server to only allow certificate based access, in additional to the best practise of not allowing root logins. This ensures great security, in addition to it being much more convenient. If I were to lose the certificates, then I can always login directly on the device.

For each git repository, I create a new folder with the .git suffix.

mkdir /data/git/myproject.git

Actually make this a git repository by running git init --bare.

# Run this as the git user
cd /data/git/myproject.git
git init --bare

On your development computer, add the Pi as a remote to your git repository.

git remote set-url pi git@

Push it to the remote and then, voilá, you’ve just used your Pi as a git server!