How to Create a shared Git Repository in Debian (ssh, git-daemon, gitweb)
Git is a distributed revision control system.
We are going to create a remote shared git repository and add the following functionality to it:
- Read and write access using ssh protocol.
- Anonymous read only access via git-daemon.
- Browse every git repository via web.
- Send an email notification when user pushes a commit.
This article shows how to set a Git repository in a Debian distro (Sid).
Create the repository in the remote machine
First we are going to configure the remote machine where the git repository will be installed.
Create a directory where we will place every git repository:
$ mkdir /gitrepo
Install git
$ sudo aptitude install git
Every user able to read and write to the git repository must pertain to gitgroup group.
$ sudo groupadd gitgroup
$ sudo chgrp -R gitgroup /gitrepo
$ sudo chmod g+w /gitrepo
Generic home for users pertaining to gitgroup group:
$ sudo mkdir /home/gitgroup
$ sudo chgrp -R gitgroup /home/gitgroup
We add our current user to gitgroup group.
$ sudo adduser my_user gitgroup
Changes will become effective after login in again.
$ groups
my_user sudo gitgroup
We create now a bare git repository
$ cd /gitrepo
$ git init --bare --shared=0664 my_git_project
Initialized empty shared Git repository in /gitrepo/bar/
NOTE:
0664: other user has read only permissions.
0660: other user has no permissions.
$ chgrp -R gitgroup my_git_project
--shared option sets directories, new files etc to the right permissions.
Now we have a bare repository where we could upload our commits or another preexisting repository.