Shared remote git repository

Creating a remote and shared Git repository (on a Linux/Unix server) is easy.

I perform this operation ALL THE TIME so I thought I’d write it down, once and for all.

remote$ mkdir /var/git/myrepo.git
remote$ cd myrepo.git
remote$ sudo git init --bare --shared

(For some reason) we need to change the value of the property shared in the config file.

shared = group

Since there will be multiple commiters and pushers, we need to set the group of the repository to some mutual group and then set the group sticky bit. This ensures us that directories and files created in the repositoey will get the chosen group id instead of the user’s primary groups. The primary groups would have prevented users to commit to the repository.

remote$ sudo chgrp -R .
remote$ sudo chmod -R g+w .
remote$ sudo chmod g+s .

On the local machine, we cd into the local project directory.

local$ cd project
local$ git remote add origin ssh://
local$ git push -u origin master

If you like to push all the refs and branches, you could go

local$ git push -u origin '*:*'

but remember that all means ALL.

Leave a comment