Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a staging site that is a working directory of a git repository. How to set up git to let a developer pull out a branch or release without changing the group of the modified files?

An example. Let's say I have two developers, robin and david. They are both in git-users group, so initially they can both have write permissions on site.php.

-rw-rw-r--  1 robin git-users   46068 Nov 16 12:12 site.php
drwxrwxr-x  8 robin git-users    4096 Nov 16 14:11 .git

After robin-server1$ git pull origin master:

-rw-rw-r--  1 robin robin       46068 Nov 16 12:35 site.php
drwxrwxr-x  8 robin git-users    4096 Nov 16 14:11 .git

And david do not have write permissions on site.php, because the group changed from 'git-users' to 'robin'. From now on, david will get a permission denied, when he tries to pull to this repository.

share|improve this question
up vote 1 down vote accepted

This is best addressed with setting the permissions on all of the directories. If you set the the group 'sticky' bit, all files in the directory will maintain the group of the directory when members of the group modify them. So, to quickly set this on the staging site do the following:

chmod g+ws [directory]
find [directory] -type d -exec chmod g+ws {} \;
find [directory] -type f -exec chmod g+w {} \;

The first command sets the write and sticky bits for the group on the site top level directory. The second then finds all subdirectories of the top level folder and does the same. The third then makes sure the the group has write access to all of the files.

When you initially create the git repository, you can have it do the above automatically by using the --shared option:

git create --shared [directory]
share|improve this answer

Try with git submodules, that should be solution to what you need.

Or if you really don't want it, you can implement some scripts for this that will stash some files before pull and then pop them out, but this will also make you problems later with merging.

share|improve this answer
I don't really get it. How would a git submodule help me? – mimrock Nov 20 '12 at 10:01
With git submodule different users can have control over different submodules, not clashing with each other, exactly what you asked for. Or, I had situation once with script which was stashing some files, run by some users, and then doing stash pop when it's run by other user, but the big issue here is merge conflicts, which you however have to resolve... – Dejan Menges Nov 20 '12 at 22:08
I'm not sure I get you. Do you suggest to create a new, empty repository, and put the whole project into the root as one submodule because 'git submodule update' will not mess with the groups? – mimrock Nov 21 '12 at 14:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.