Wednesday, June 1, 2011

Sharing your Git repository

Out of the several configuration parameters provided by Git..."core.sharedrepository" is one of the most important parameter which enables your GIT repository to be shared within/ outside your development team.

By default - GIT repositories are not shareable and can be used only by 1 person.

for e.g. if a developer X add a new file than any other developer apart from X will not be able to update the same file.

The reason behind is that the GIT repositories are created in an non-Shareable mode and the files created in the repository are in read only mode, which can be updated only be the creator and not by anyone else.

Here are the steps which will enable your repository being shared among group of developers (on Unix): -

1. create a group which will be assigned to all developers working on Git

   groupadd {group-name}

2. Now assign the primary group of all new or existing users (who needs to work on git) same as what we have created in #1.

   for new users : - useradd -g {group-name} {username}
   for existing users : - usermod -g {group-name} {username}

3. Define GIT_DIR as global variable pointing out to the physical location of the GIT repository

   export GIT_DIR=<Physical Location of your Git Repo>

In order to make this variable available globally you can also define the above parameter in /etc/profile or create a new sh file in /etc/profile.d/*sh

4. Execute the following Command in your Git Repository

   git config --add core.sharedRepository group

The above command will enable your GIT repository to be shared among group of developers.
i.e. Now the repository is in group writable mode, where all users in the same group (as defined
in #1) will be able to read and write, to/ from the repository.

Apart from "group" there are other parameters which are explained very well in the documentation: -

"When group (or true), the repository is made shareable between several users in a group (making sure all the files and objects are group-writable). When all (or world or everybody), the repository will be readable by all users, additionally to being group-shareable. When umask (or false), git will use permissions reported by umask(2). When 0xxx, where 0xxx is an octal number, files in the repository will have this mode value. 0xxx will override user’s umask value (whereas the other options will only override requested parts of the user’s umask value). Examples: 0660 will make the repo read/write-able for the owner and group, but inaccessible to others (equivalent to group unless umask is e.g. 0022). 0640 is a repository that is group-readable but not group-writable. This attribute is false by Default."
Also see git-init to do the same while initializing the repository

5. Lastly fix the permission on the existing directories create in your GIT repository

   sudo chgrp -R coders .
   sudo chmod -R g+ws .

Thats it...from now on any new developer just needs to be added in the same user group (created to git developers) and he/ she will be able to participate in the development.

No comments: