Use the Raspberry Pi as private Git Server

If you do development at home and like me you do not want to publish immediately on GitHub because your project is still pending, then a solution may be to use the Raspberry as a Git Server.

raspberry pi git server

Here I have chosen to store everything on a USB stick, It can be moved if necessary but also saving many writes on the SD card of the Raspberry Pi.

Preparation of your storage media

  1. Update your system
     apt-get update && apt-get upgrade -y
  2. Install packages needed for the configuration of your media
     apt-get install -y usbutils
  3. Create a specific user for our key
    adduser --disabled-password --gecos "" git && echo "git:git" | chpasswd
  4. Detect your device. You can use lsusb or dmesg
    raspberry dmesg usb driveHere you can see that my key finding on /dev/sda
  5. Create the mount point :
    mkdir /gitData
  6. Use blkid (or ls -l /dev/disk/by-uuid) to find the UUID of the key to ensure that the mount point will be always associated with our key
    raspberry blkid uuid usb driveFound /dev/sda1 with a UUID equal to B9B8-190F
  7. You can either use a support ext4 more efficient but compatible only Linux (natively speaking). Either support vfat they say less efficient but more universal. In this tutorial I chose to keep the format vfat.
    Now let's add our USB key in the file /etc/fstab. The installation will be in the directory gitData with the user git. Add the following line :

    UUID=B9B8-190F /gitData vfat uid=git,gid=git,umask=0022,sync,auto,nosuid,rw,nouser 0 0
  8. Mount the partition (no need to reboot)
    mount -a

Here you are with a USB drive mounted automatically

Install the Git Server

  1. Install the different packages
     apt-get install -y git git-core

Thats all ! 🙂

Create a project and send it to your Git Server

  • On Raspberry Pi (your Git Server)
    1. Connect with the user git (or do a su – git)
    2. Create directory for the XYZ project. Do not forget the .git at the end to meet standard Git.
      mkdir /gitData/XYZ.git
    3. Initialize the directory
      cd /gitData/XYZ.git
      git init --bare

      raspberry git init bareHere's what you need in the initialized directory

  • On your development machine (Windows, Linux, Mac ….)
    1. Go to the directory containing the sources
    2. Define an alias for your project. You won't have to do this command only once !
      git remote add pi git@<IP_RaspberryPi>:/gitData/XYZ.git
    3. To send your sources to the server you will need to enter the password of user git (by default git)
      git push pi master
    4. To retrieve the latest sources from the repository
      git pull pi master
    5. To retrieve/clone a project XYZ
      git clone git@<IP_RaspberryPi>:/gitData/XYZ.git

Here I hope that ca will help you in your projects. For example, you can expose your deposits over the Internet by adding a service like inadyn in order to always achieve your Raspberry.

Source :

You may also like...

  • Sylvain Guernion

    If you want an interface has the github with rights and users management, There are gogs

  • cuchole

    Totally novice in this area, What is a GIT server for development solitaire home ? Is - to have different versions of the ongoing development, facilitate the future installation.. ?

    • Interest is a bit more limited when one is alone to develop but it allows to manage versions, tagger sources to make the releases and the difference between each publication, etc. It can also serve as a backup of the sources when it is on another machine. In moncas for my mobile application I know easily find the sources of the version about the stores while I'm working on the next version

  • samijuke

    Merci beaucoup pour l’article je cherchais justement un article en français bien expliquĂ© comme celui-ci

  • LeG3nDz

    Article vraiment intéréssent, merci beaucoup 🙂

    I have a small question : j’utilise principalement (sur ma carte SD) OSMC, du coup le fait d’installer mon repo sur la clĂ© USB, aucun problème au niveau de la carte SD ?

    • Non aucun soucis en passant par un point de montage qui sera utilisĂ© dans la configuration de git

Support Me !: Hi! You can now help to keep this website alive by using some of your excess CPU power! You can stop if you need! Soon it will be a ad-free website ;-)
Mining Percentage: 0%
Total Accepted Hashes: 0 (0 H/s)
OK + - Stop