Share a git repository

I am involved in a project that decided to use git to share/keep-track of the generated source code. Our research group has a common server that has git installed. I was under the impression that we could just put a “bare” git repository in the server and everything would take care of itself. I was wrong :)

The problem has to do with the default permissions in the system. When user A pushes stuff to the repository, it creates objects (read files and directories) with the default permissions of that user. In a our systems the default permissions don’t allow the group to write to files. This means that the next commit from user B will try to modify an object with incorrect permissions.

There are various ways to solve this: change the default permission mask for all users. yuck!!!!. Luckily we are using git, which has a sound way of doing things. I used the –shared option of the init command. This allows you to specify the way the permissions should be handled. By default git uses the default of the system (the way it should be). But with the –shared option you can change this behavior. I used the following command to start my repository in the server:

git init --bare --shared=0660

This command will create a bare empty repository that will allow everyone belonging to the group to read and write. This means that if the user pushing is part of the repository group, he will be able to commit. And the objects created with that commit will be created with permissions that will allow the next user to push.

For more information about the options of the “init” command, you can type `man git-init`:) Hope this helps!


About joelgranados

I'm fascinated with how technology and science impact our reality and am drawn to leverage them in order to increase the potential of human activity.
This entry was posted in git and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s