Skip to content
Apr 27 / John Wyles

Creating a Shared Git Repository For Multiple Users

It took mashing together multiple articles, blog posts, and wikis to put this all together but I finally have a process for hosting a “centralized” shared git repository that honors file permissions for the respective users. The way in which you do this is the following:

On the server:

# Create a git repository
sudo mkdir -p /var/git
cd /var/git
sudo mkdir myproject
pushd myproject
sudo git init
sudo touch .gitignore
sudo git add .gitignore
sudo git commit -a -m 'Initial import'
popd

# Clone the bare git components away
sudo git clone --bare myproject myproject.git
pushd myproject.git

# Set the type of shared repository this will be
sudo git config core.sharedRepository group
popd

# Change the file permissions
sudo chown -R root:users myproject.git # Replace "users" with your group
sudo chmod -R g+ws myproject.git

On the clients:

git clone username@example.com:/var/git/myproject.git

That should be the basics without going a step further and creating a “git” user and group to host the service as. Enjoy!

Leave a Comment