Headless Git Server
This short tutorial explains how to configure a small git server, which can maybe run on a Raspberry Pi. To use this git server, no webserver or other fancy stuff is required. Access is only performed via ssh. The tutorial also includes how to specify a different port for the ssh service, if you don't use the default port. So it's possible to use the existing ssh service on a server and it's only required to install the git service. Hence, the first step is to install the git package via apt-get:
sudo apt-get install git
The next step is to configure a new user, which is only in use to connect to the git server via ssh. If you want to use an existing user, you can skip the following step. For security reasons, this user shouldn't be an administrator account.
pi@testsystem:~# adduser git
Adding user `git' ...
Adding new group `git' (1002) ...
Adding new user `git' (1001) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
Use a long and complex password for this new user, to prevent easy bruteforce attacks.
The last step for the server configuration is to initialize a new empty git repository, in the home directory of the previously generated git user. This step has to be done for every new repository you want to create.
# Change into the home directory of the git user
cd /home/git
# Create a new git repository directory
mkdir project.git
cd project.git
# Create a repository in the directory project.git
# wihout a working directory
git --bare init
Now you can generate a new repository on your local PC and connect this to the remote repository on the server:
# Config for the client (laptop, pc)
mkdir projectfolder
cd projectfolder
git init
git add .
git commit -m "Initiale commit"
# Port is optional and can be removed
git remote add origin ssh://<gituser>@<server>:<port>/home/git/project.git/
git push origin master
That was everything you have to configure to setup a very small git server.
If you want to change the location of the remote server, use the following command:
# Change the remote origin
git remote set-url origin <ssh://<gituser>@<server>:<port>/path/to/project>