GitPi: A Private Git Server on Raspberry Pi

Git is usually used in synchronization with GitHub — the former is a source code management system and the latter is a website where you can share/contribute Git repositories with the larger internet community.

For those wanting to get started with GitHub, I’ve written this Instructable: Introduction to GitHub.

But, what if you want to keep your repositories private? The usual answer is that you have to pay for this service. Boo.

A lot of us have code-in-progress that we want to properly put onto the Git system, but ins’t ready for public consumption. Nor do we want to pay for the service of private hosting.

However, using the Raspberry Pi, you can set up your own Git server on your home network.

This Instructable will cover setting up your Raspberry Pi as a Git server with repositories saved onto an external USB thumb drive. My example uses the Mac OS, but can be extended to other platforms as well.

You should already have Git installed on your laptop and know the fundamentals of how to use it. Check out the Introduction to GitHub Instructable if this is not the case.

I’ve used two sources to figure out how to set up GitPi: a guide  by Thomas Loughlin and one by Monkey Hacks.

They’re both good, but neither one did exactly what I wanted or explained it fully, which is one reason I wanted to write this Instructable.GitPi A Private Git Server on Raspberry Pi

Step 1: Set up your Raspberry Pi for ssh

First, setup a Raspberry Pi for ssh access and that it’s on your home wifi network, which means that you can log into it from your laptop.

I wrote this Instructable: Ultimate Raspberry Pi Configuration Guide, which covers how to do this.

Once you go through these steps, you’ll be able to transfer files to your Raspberry Pi via the Terminal application.

Note: I’m using a Mac for this Instructable, but you can extend this to other platforms.

Step 2: Init the USB thumb drive

We will save all the Git repositories onto a USB thumb drive, rather than the Raspberry Pi’s SD card.

This will give you an independent storage drive for your Git repositories, which is easily-readable on your laptop.

Open Disk Utility. Erase the USB drive, format as MS-DOS (FAT) and call the volume GITPI. I also use a labelmaker to affix a label on the back so it doesn’t get mixed up with my other USB thumb drives.

Mine is 16gb, which should be plenty.

Step 3: Run latest package updates

Connect via ssh into your PI. My IP address for the SD card for this is 10.0.1.64. Yours may be different — just change the address accordingly.

Open the Terminal window and on the command line, type:

ssh [email protected]

Run the latest package update and upgrades, just to make sure everything is current.

First the update:

sudo apt-get update

Then the upgrade:

sudo apt-get upgrade

Then reboot:

sudo reboot

Step 4: Install Git on the Raspberry Pi

Install git:

sudo apt-get install wget git-core

You’ll see terminal output. In this case, the packages were already installed (maybe with the update/upgrade from last step), but you see some sort of success at this point.

Now, turn off the Raspberry Pi by unplugging the micro USB power cable.

Step 5: Permanently mounting the USB drive

Put the formatted USB drive into the Raspberry Pi. And turn the Pi back on.

I’m not sure if this matters, but I always leave the wi-fi dongle in the lower USB port and use the upper one for the external USB drive/keyboard/other things.

Wait a few seconds and then ssh back into the Pi.

ssh [email protected]

What we then type in;

mkdir usbdrv

What we are going to set up is a mount point — a way to always map this directory to the USB drive.

now, type in:

sudo blkid

check out output — we are looking for the USB drive device info, which is easy to identify because we called it GITPI when we initialized it.

Mine reads:
/dev/sda1: LABEL=”GITPI” UUID=”6D34-1514″ TYPE=”vfat”

This should be the similar on yours: /dev/sda1 is the USB thumb drive device.

Now, we are going to edit what is called the file systems table to make the USB drive map into the usbdrv directory

Type in:

sudo nano /etc/fstab

Here is the tricky part. We are going to modify the fstab file so that this device maps to the usbdrv directory.

add the line to the end of the file (you can copy and paste this line)

/dev/sda1 /home/pi/usbdrv vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0 0

important: this is 1 line, not broken up over two lines (the Instructable is doing weird things to the formatting).

What this does is to map the /dev/sda1 device — any thumb USB drive to the usbdrv directory. The flags are ones that I cribbed from the Thomas Loughlin guide. Admittedly, I’m not sure exactly what they do, except for allow the drive to be a read-write drive and not tied to a specific user.

Cntl-X, Y, Return to save.

Then restart:

sudo reboot

If you want to learn more about drive-mapping and mounting, this eLinux Guide has a lot more information.GitPi A Private Git Server on Raspberry Pi schematic

Step 6: Test the USB transfer

After your Pi reboots, you’ll have to ssh into it again.

Then, on the command line:

nano usbdrv/test.txt

This will create a text file in the usbdrv directory — which is actually the USB thumb drive itself called test.txt. Put some text in the file, like mine pictured here.

Cntl-X, Y, Enter to save

At the command line:

ls usbdrv

And you’ll see a lone file, test.txt.

Turn off the Raspberry Pi. Pull the thumb drive and mount it onto your laptop.

Presto! You can read the text file on your laptop. Delete the file, pull the drive, put it back into your Raspberry Pi and power the Pi back up.

The cool thing is that the Git repositories can be read by your computer and are not tied to the Pi. The usbdrv will always mount to whatever USB drive you put into the Pi. If you have source code overflow problems, you can always swap out USB thumb drives.

 

For more detail: GitPi: A Private Git Server on Raspberry Pi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top