Thursday, March 24, 2016

Setting up Your Raspberry Pi as a Git Server

Git to Raspberry Pi

Managing versions of a project is useful. Even if your project is private, it’s always a good thing to be able to retrieve an old version, if (for instance) the new one is broken for some reason.

To manage versions of a project, we can create a new folder for each new version but, today, we have great tools that allow us to do far better.

One of these tools is Git. Git is great for managing versions of a project, whether you’re alone working on this project or not. This tool can be used on a single computer without any problem. However, if you want to share your code between several computers, you’ll need a Git server. That’s what we’ll build in this tutorial.

First I’ll explain what we’ll build, and why we need it. Then, we’ll see concretely how to build our server with a Raspberry Pi. Finally, we’ll see how to use our server.

What Do We Want to Do?

A Git server?

Git logo As said above, you can use Git on a single computer, just to manage versions of a private project. The problems come when you want to share your code, either publicly or between two or more of your computers.

In this case, you need a place to send your modifications, so they can be retrieved on the other computers. This place is a server.

With this server, the process will be as follows:

  1. you modify your code
  2. you send your changes to the server
  3. on another computer, you or anybody else downloads the changes from the server
  4. new changes are made from this other computer
  5. these changes are sent to the server so that others can download them, and so on.

A Git server is basically a computer connected to the Internet on which we can store Git repositories. Any computer can be used for that and, here, we’ll use a Raspberry Pi, as it has the advantage of being a very low cost option, while giving good performance.

Why create our own server?

There are various services around the Web that allow us to share Git repositories—like GitHub, which is one of the most popular.

The problem is that repositories on services like these are often public. Sometimes, we don’t want to share our code publicly, but rather to share it with just a few people (or even just another computer we own).

Some services like GitHub offer private repositories — so that you can choose who sees your code — though they’re not free. That’s why creating our own server can be a good idea.

We’re not recreating GitHub here

Just to be clear, though: we’re not attempting to replicate GitHub with a simple Raspberry Pi. The server we’ll create is a very simple one, with all the features Git has, but no more. So there won’t be the facility for things like pull requests, or even a graphical interface.

Even if simple, though, this server will be far from useless. I currently have a Git server on my Raspberry Pi. I use it to share code between my desktop and my laptop. I use GitHub for some projects, but not for all of them. For some private projects, or for experimental things I don’t want to share for now, I use my little server. That way, I can work from any computer without having to publicly share my code.

What will we need?

There are several versions of the Raspberry Pi, from the very small and cheap Raspberry Pi Zero to the recent and powerful Raspberry Pi 3. Which should you choose for your Git server?

I didn’t test on a Raspberry Pi Zero, so, to be honest, I won’t be able to say if this one is sufficient (I think it is, though). However, the very first version of the Raspberry Pi is largely enough and, as the Pi 2 and 3 are available, maybe you can find the first Raspberry Pi for a small price, so it’s a good option to think about.

Anyway, the Raspberry Pi is just a motherboard. Whatever version you choose, you will need at least a case to protect it, a power source (via microUSB, like a smartphone), an SD card to store the OS (a classical SD card or a microSD following the version of the Pi you chose) and a way to connect the Pi to the Internet. Depending on the Pi you have, you can connect it through Ethernet, directly via Wi-Fi (for the Pi 3) or with a Wi-Fi key.

Now that you have everything you need for this project, let’s see how to get a Git server from this small computer!

Continue reading %Setting up Your Raspberry Pi as a Git Server%


by Jérémy Heleine via SitePoint

No comments:

Post a Comment