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.
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.
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.
ssh [email protected]Run the latest package update and upgrades, just to make sure everything is current.
sudo apt-get updateThen the upgrade:
sudo apt-get upgradeThen reboot:
sudo reboot
ssh [email protected]What we then type in;
mkdir usbdrvWhat we are going to set up is a mount point — a way to always map this directory to the USB drive.
sudo blkidcheck 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.
sudo nano /etc/fstabHere is the tricky part. We are going to modify the fstab file so that this device maps to the usbdrv directory.
sudo reboot
nano usbdrv/test.txtThis 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.
ls usbdrvAnd you'll see a lone file, test.txt.
cd /Users/scottkildall/PythonScripts/justdiedbot git initNow, do a similar thing on your Raspberry Pi. In a second Terminal window, ssh back into the Pi. We are going to create a directory called justdiedbot and initialize it with Git. Once again, substitute your source directory names rather than using mine.
mkdir usbdrv/justdiedbot.git cd usbdrv/justdiedbot.git git init --bareThis creates a new directory with a .git extension and an empty Git repository. For the geeks in the audience, here is a detailed discussion of what the --bare flag does.
Note: some readers of this Instructable have reported that you need to call "sudo" before the git init steps, so if you have permissions errors, type in: "sudo git init"
cd /Users/scottkildall/PythonScripts/justdiedbotOf course, you should type in your local directory path. One trick with the Finder is that you can drag-and-drop the folder to complete the path, typing in 'cd ' and then drag the folder into the Terminal window.
git remote add pi [email protected]:/home/pi/usbdrv/justdiedbot.gitYou only have to add the remote one time. From here on out, we will refer to this remote as pi.
If you put the USB thumb drive back onto your laptop, you'll have access to all the Git files, seen here.
For future source code management for a project, simply repeat step 9.
To add more projects, repeat source code steps 7-9.
This is completely compatible with GitHub, since you'll be using a different remote for GitHub, so when you're ready to go public, you can put your repositories on GitHub and still use your Pi as your home backup.
I hope this was helpful!
Scott Kildall
For more on Raspberry Pi code and other projects, you can find me here:
@kildall or www.kildall.com/blog