File ownership/group is changed when users push to a GIT repository

For over a year, I’ve been having troubles with GIT and directory/file permissions. I have a central repository to which multiple developers push code, using ssh (origin set up as ssh://example/git/repository). I have set up the repository as follows:

1) My config file in the central repository:
[core]
repositoryformatversion = 0
filemode = true
bare = true
sharedrepository = 0660

  • Automatically apply “git update-index --chmod+x” to executable files
  • why my file permission being changed after pull from git repository
  • How to read the mode field of git-ls-tree's output
  • Storing file permissions in Subversion repository
  • why git fast-import file modes are hardcoded?
  • Git diff reports local changes 'old mode' / 'new mode'
  • 2) All repository directory permissions are set to 770 (rwxrwx—)
    3) All files in ./objects/XX and ./objects/info are set to 440 (r–r—–)
    4) All other files are set to 660 (rw-rw—-)
    5) Ownership is set to root:group_name

    (note that this came from the reccomended setup in the top response in this thread: Making git push respect permissions?)

    All accessing users are members of the group ‘group_name’.

    The problem is that if user1 pushes to the repository, the file ownership on some files are set to user1:user1 – meaning that the group is changed. Once this happens, no other users can push (or pull) from the repository, as they do not have permission to read, write or execute from required files in the repository anymore.

    I have read every thread I can find regarding the matter on Stack Overflow and pretty much everywhere else on the net, but I keep running into this same issue.

    The problem is, I’m not sure if this issue is one of GIT, or one of UNIX, and I’m not sure how to fix it. How can I stop the group from being changed when a user pushes to the repository?

  • Rebase a branch that has child branches
  • When deleting remote git branch “error: unable to push to unqualified destination”
  • Git repository from one machine to another
  • Prohibit remote pushing to the master branch in git
  • SSH Key - Still asking for password and passphrase
  • git without bash/cygwin
  • One Solution collect form web for “File ownership/group is changed when users push to a GIT repository”

    It looks like you changed the core.sharedRepository after initializing the repository rather than using init --shared=group which should set the permissions up correctly. This means that the sgid bit won’t be set on the git repository’s directories correctly. You will have to fix this manually with something like (assuming GNU find and xargs):

    find . -print0 | xargs -0 chgrp group_name
    
    find . -type d -print0 | xargs -0 chmod g+s
    
    Git Baby is a git and github fan, let's start git clone.