Search code examples
gitunixpermissionsfile-permissions

How to use group file permissions correctly on a git repository?


We're accessing a shared git repository via file paths, for various reasons I'll omit for now, created with --shared=group.

We have various unix groups but all share a common group. If I run a chgrp -R on the git repository everyone can read from it, but if someone writes to it more often than not new files are created which do not use the common group.

This problem appears to be because our primary group is not the shared one and if we run a newgrp all seems to work well.

There are issues with this approach though; newgrp is slow and it spawns a new shell, which makes me think calling it in a .bash_profile would be a bad idea, without even considering whether or not we'd want all our new files to use the common group. Relying on memory to run it before doing any git work seems like a recipe for disaster too though.

So... any suggestions?


Solution

  • You need to set the setgid bit on the group as well.

    chgrp -R GROUP /path/to/repo
    find /path/to/repo -type d -print0 | xargs -0 chmod g+s