Git and Linux group access
For a recent project I had to setup a remote Git repository that was going to be used by multiple contributors. I had a few issues with permissions that I had to work thorough, so I thought I would make a note of them in case anyone else has similar issues.
I first created a new Linux user for the project and then created a bare Git repository by following these instructions in the new users home directory. For examples sake lets say that the new git repository is owned by the work user with the work group.
I then created new user accounts for each of the developers. This would allow them to have ssh access to the box and commit to the repository.
I then added each new user to the work group by using the following command:
usermod -G [group_name] [user_name]
So I thought that was that, but then I came across a few problems and found out that I also needed to change the default group of the new developer accounts I created. This would enable the user to maintain the correct group ownership when they change the repository (through git pull for example). In our example it will make/update files with the group work
To do this I did:
newgrp [group_name]
To verify the default user group just type in this command whilst logged in as the user.
id
The first gid should be set to the new group. Or you could just create a file and have a look at the group ownership.
I also found out that I need to add the following line into my config file under my remote git repository
sharedrepository = 1
It all seems to be working correctly. Multiple people can commit to the repository and they can do git pulls on the server maintaining correct group permissions.
References:
Image from : silversprite
Comments