Gitlab is a web-based free and open source Git repository manager much like Github. These version control services both utilize the Git version control system originally created by Linus Torvolds under the GNU GPL v2 license in 2005. There are many Git services now, but the two biggest providers, Github and Bitbucket, require paid plans to use private repositories or self-hosting. Which is where Gitlab comes in with the option to install the server software on your own machine. Gitlab is available on a wide variety of devices, including the beloved Raspberry Pi 2 and 3. Why go through the trouble of installing Git at home? Having your own local Git server has a few advantages: you will always have access to your source code regardless of the state of your internet connection, power grid, or download/upload speed. Most importantly — you control your own data. A Raspberry Pi Git server is also a great way for a hobbyist or newcomer to get familiar with the Git protocol and development workflow as they need not worry about finding a public project to contribute to, and whether their contributions will be “good enough”.
There are a few guides out there that list the basic steps of how to install Gitlab on the Raspberry Pi 2, but they aren’t 100% comprehensive. I will try to cover each step as thoroughly as possible so you don’t ever get left scratching your head.
Requirements gather your tools
You should know what you need to complete this before you start. You’ll need:
– A Raspberry Pi 2 or higher (Raspberry Pi 3 is even better)
– A 16+ GB Sd card (the install is just under 5 GB, so make sure you have room for your project files)
– Essential peripherals: power supply and ethernet cable
– A way to connect to the Pi through SSH (see how to enable by default here, step 4: https://caffinc.github.io/2016/12/raspberry-pi-3-headless/)
– if you don’t want to enable SSH this way, you’ll need to hook up the Pi to a monitor at first boot and enable it (https://www.raspberrypi.org/documentation/remote-access/ssh/README.md)
– Internet access
1. Preparing the installation media, OS, and flashing software
We will start with a fresh install of Raspbian and install the server on top of it. Go to the official site and download the latest image of Raspian Stretch Lite, headless preferably. Download an image flashing program of your choice. For Windows, Wind32DiskImager works flawlessly. For Linux and Mac there is UniveralUSB installer.
2. Installing the Gitlab server software easiest server install yet
Once you’re booted up and logged in (username pi, password raspberry) you can begin with the standard installation steps found on the Gitlab website with a few exceptions. Do not attempt to configure a mail server, just leave that option blank when it pops up. After that, Postfix will prompt you to select “internet site”, just choose “local” instead since this will be for your home/office network. Once you’ve followed all these steps, enter the Pi’s IP address (type in “hostname -I” into the terminal) in your browser to open your new Gitlab server’s page.
Create a password and login as “root”. You should now see the projects overview page, pretty neat right? You can start your own project from here and figure out the Git administration side of things on your own, it’s all fairly intuitive except for maybe what I’m about to explain. You will need to create the project folder from the web UI before continuing.
3. Setting up users, permissions, and authentication the part that could be simpler
This is the part that a lot of guides skip over. Chances are if you’re using a Pi as a local Git server you’ll also want to be accessing it from more than one other device (Desktop, laptop, remotely through VPN). You need to add a user and SSH key for each additional device. You can just use made up emails like firstname.lastname@example.org since everything is local. You can use the default “Administrator” login for now or create a new user. Go to user settings –> ssh keys. If you are on Linux, creating a key is as simple as
ssh-keygen -t rsa -C "GitLab" -b 4096
and then copying it to your clipboard like (might need to apt-get install xclip)
xclip -sel clip < ~/.ssh/id_rsa.pub
And paste it into the box on the SSH key page, give it a title and you’re set. If you’re on Windows or Mac, there are instructions for those systems too at yourraspberryipaddress/help/ssh/README
The only changes left to make to the server are project privileges and the protocols you can access with. Go to edit project and make sure your user has the privilege to alter the master branch.
Now we’ll set things up so you can push your project onto your Pi. Make sure you have Git installed on your work computer as well. Navigate to the project folder you want and enter these commands (assuming you continued with the “Administrator” user):
git config --global user.name "Administrator" git config --global user.email "email@example.com"
On the project home screen, just below the project title, you will see the URL. It is different depending on whether you want to access via HTTP or SSH, and you need to replace “raspberrypi” with its IP address. Copy it and swap in the IP address.
git init git remote add origin git@raspberryIP:root/projectname.git git add . git commit git push -u origin master
You’ll be prompted for your username and login. If you set up everything correctly you should now have just made your first commit, congratulations!
Conclusion a fine Pi project indeed
Gitlab has a really nice web UI that makes managing projects much less painful. Sure you can do the same thing with Github or Bitbucket for free, or privately, but not both. And you also have to
buy a Raspberry Pi and do all this boring setup stuff yourself. But you’ll also gain more control and privacy over your code, as well as a local backup of your project. Some of the pages don’t load instantly (see: today’s standard) and it doesn’t help that Gitlab is running on a Pi, but the main functionality works just fine. As a next step, you could even install your own Gitlab server with the cloud provider of your choice.
It is possible to modify the settings to make GitLab run on a Pi:
sidekiq['concurrency'] = 3 unicorn['worker_processes'] = 3 postgresql['shared_buffers'] = "128MB" postgresql['max_worker_processes'] = 2 nginx['worker_processes'] = 2
Alternatives lightweight Git web interfaces
- Gitea (available on FreeBSD through ports, through brew for Mac, as a Docker image, or source)
- Gogs (install from binary, compile from source, or with these package mangers)
Further Reading may answer some questions you have
- Careful, SD cards aren’t renowned for their longevity
- But you might actually need that swap
- Using hard drives with your Pi: