10 August 2021

I really could use a git server at home and I already have Raspberry Pi4 functioning as a application server on the home network. I little Googling and reading the git documenation later and I now have a functional git server.

Keeping it Simple

Git is a distributed source control system so it works fine in a file based mode.

Create a bare git repository.

$ cd ~/src
$ git clone --bare website website.git

Generate a new RSA key pair for this connection.

$ ssh-keygen -t rsa -b 4096 -C bipedalprog@appserver01

I used the output file name of "/home/bipedalprog/.ssh/bp_appserver01".

Add your identity to the ssh daemon.

$ ssh-add /home/bipedalprog/.ssh/bp_appserver01
Identity added: /home/bipedalprog/.ssh/bp_appserver01 (bipedalprog@appserver01)

Now copy your identity to the server. This assumes that you have an account on the system.

$ ssh-copy-id -i ~/.ssh/bp_appserver01 bipedalprog@appserver01

You should see

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/bipedalprog/.ssh/bp_appserver01.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
bipedalprog@appserver01 password:
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh bipedalprog@appserver01"
and check to make sure that only the key(s) you wanted were added.

Server Side

Create a group to allow collaboration in git.

$ addgroup git

Add your user to the group.

$ sudo usermod -aG git bipedalprog

Create a directory to receive git repositories.

$ sudo mkdir /data/git
$ sudo chgrp -R git /data/git
$ sudo chmod -R 2775 /data/git

Back on the development machine. Copy the local repository to the shared server.

$ scp -r website.git bipedalprog@appserver01:/data/git

After you have copied your local repositories to the server you can ssh to the server and run the following in each repository directory. (It will not remove previous history.)

$ cd /data/git/website.git
$ git init --bare --shared

Test It

Let’s check that we can clone the repository on our development machine.

$ mkdir -p ~/tmp/gitest
$ cd ~/tmp/gitest
$ git clone bipedalprog@appserver01:/data/git/website.git

Mission Accomplished

You should now have a second home for your git repository and a useful way to share it with others in your local network. Adding other users to the server and placing them in the git group is all it takes to share the ssh git repository.