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

  • How can I make my local Git repository accessible for multiple users?
  • why git fast-import file modes are hardcoded?
  • How do I preserve DIRECTORY file mode or permission in git?
  • Storing file permissions in Subversion repository
  • Mercurial: Ignore file permission / mode (chmod) changes
  • Git is changing my file's permissions when I push to server
  • 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?

  • How to get commits information on Jenkins using Groovy since last successful build?
  • Which is more suitable on Windows, git or mercurial?
  • Change threshold on the similarity index for git merge with renaming involved (like -M --find-renames on diff)
  • Git bash is not showing for another useraccount on my windows
  • Apply a command to all commits
  • Git sh.exe process forking issue on windows XP, slow?
  • 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.