Click here to Skip to main content
965 members (128 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

14.2K views
Posted 4 Mar 2014

Setup a Git server on your Raspberry Pi

, 4 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Short and easy description on how you get your own, private Git server running on your Raspberry Pi

Introduction

The Raspberry Pi made it quickly to many programmers home, and is used for various purposes. I have one running as scan server, where the multifunction printer stores the scanned PDF files to be accessed from every device on the home network. Since I do a lot of pet project coding and want these projects under a source control, I decided to set up another Raspberry Pi as Git server.

Preparation work

First of all, you need a Raspberry Pi which is set up with the latest version of the  Raspbian OS. You need to install Git and SSH on the Pi, therefore an Internet connection is needed, too.

To install Git, run the command

sudo apt-get install wget git-core  

This downloads and installs the latest Git version onto your Pi. Afterwards run

sudo apt-get install ssh

to install SSH support. After the installation, you theoretically need to start SSH after every boot of your Pi. Because this is cumbersome and nothing really pleasant, you need to automatically start SSH after every boot. You can do this by running

sudo update-rc.d ssh defaults 

If you now run

sudo reboot 

your Pi reboots itself and automatically starts SSH on boot.

Set a hostname

To comfortably access your Git Server setting an easy to remember host name is recommended. Open /etc/hostnamce to set a custom host name for your Pi:

sudo leafpad /etc/hostname 

Type the host name you want to use and save the file - I picked gitserver1 as host name for my Pi.
Afterwards, replace every occurrence of raspberrypi in /etc/hosts with gitserver1 (or whatever name you decided to give). Edit the file by running

sudo leafpad /etc/hosts 

After you have done that, reboot your Pi by running

sudo reboot 

Add a Git user and user group

To use Git from remote, you need a user and a user group for it:

sudo adduser --system --shell /bin/bash -gecos 'Git user for Marco Bertschi' --group --home /home/marco marco

This creates a user named 'Marco'. You need a password for that user, therefore run

sudo passwd marco

You will be prompted to set a password.

After you have set the new password you can switch to the newly created user and initialize the first, empty git Repository:

su marco #Switch to user marco
cd /home/marco #go to home drive where user has full read/write privileges
mkdir myrepository.git #create an empty repository
cd myrepository.git # go to newly created repo
git --bare init #initialize the empty repository

Push your code to the Pi

After the Pi is set up as Git server you can push code to the previously created repository on the Pi. You can do this by creating a local repository and then pushing it to the Git Pi:

git remote add origin marco@gitserver1:/home/git/myrepository.git
git add -A
git commit -m "Initial commit"
git push origin master

Congratulations! You just have created a Git server on your Raspberry Pi and pushed code to your first repository.

Points of Interest

Git (and especially the Git Bash) can be very confusing topics for beginners - I hope that I was able to clear the dust a bit, and give beginners a good guide on how they can handle Git, but also made a Reference for experienced Git users who need to refresh their knowledge, for whatever reason it may be.
If you haven't found what you are looking for after reading this article, or maybe need some further information feel free to go through the links I provided in the chapter "Further Reading" below.

Further Reading

This chapter provides links to some sources which helped me writing this article - Git Infos are not easy to find, especially if you are looking for a different explanation which doesn't just say "type XYZ". I wanted some special sources sources which provide an overview and/or explain the background behind certain commands, or even give you Tips, Tricks, and Tweaks. Here they are:

Basic Git Command Line References for Windows Users - John Atten
A few Git tips you didn't know about - Mislav Mahronic
Git Reference

History

03-MARCH-2014
--> First publication

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Marco Bertschi
Software Developer (Junior)
Switzerland Switzerland
Software Developer (Swiss Federal VET Diploma), experienced with Qt C++, Arduino Boards, multiple communication technologies (the usual Webservices, TCP/IP bunch as well as serial port communication), and C# including WPF, Entity Framework and COM libraries built using the .Net Framework.
Music enthusiast, runner, part-time psychologist for friends, awesome guy and Air Force Sergeant First Class.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
RA-Web1 | 2.8.170424.1 | Last Updated 4 Mar 2014
Article Copyright 2014 by Marco Bertschi
Everything else Copyright © RootAdmin, 1999-2017
Layout: fixed | fluid