Difficulty: Easy
Estimated Time: 15-20 minutes

To synchronize the work on a programming project we usually use GitHub, GitLab, etc. It is also possible to install and use one of the GitHub-like systems in your own server, like:

However if you don't need a web interface, issue management, pull requests, and other fancy features, you can easily create a central Git repository on your own server and access it through ssh. This tutorial shows how to do it.

Central Git Repo With SSH

Step 1 of 4

Step 1

Setup the central server

In this step we are going to setup the server. In the following steps we will do the setup for the first user and the second user.

  1. Create user accounts.

    For each user that needs to access the central repo we will create an account on the server. Let's assume that we have two users and their accounts are named user1 and user2.

    useradd -m -s /bin/bash user1

    echo user1:pass1 | chpasswd

    ls -al /home/user1/

    Create also the second user:

    useradd -m -s /bin/bash user2

    echo user2:pass2 | chpasswd

    ls -al /home/user2/

  2. Create a group for Git:

    addgroup git-group

    In order to manage the read and write permissions to the Git repo for the users that we created, we will add them to this group:

    adduser user1 git-group

    adduser user2 git-group

  3. Create a bare Git repository for the project:

    git init --bare --shared /srv/project.git

    Central Git repositories don't have a working tree. They are called "bare" repositories and are initialized with the option --bare.

    The option --shared specifies that this Git repository is to be shared amongst several users. This allows users belonging to the same group to push into this repository.

    cd /srv/project.git

    ls -al

  4. Now let's set the right group ownership to this repo:

    chgrp -R git-group .

    chmod -R g+rw .

    chmod -R g+s .

    Notice the setgid permission that we set on the repo dir. Because of it, the new sub-directories or files that are created inside the repo dir will have the same group as the repo dir (git-group). This is convenient for a group of users that use the same directory.

    ls -al

    cd -