This typically occurs when files or folders located in the ‘.git/objects’ folder do not share certain group permissions in case of a shared repository. Following are a few actions that can help resolve it on a more permanent basis without developers need to change the default group setting:
Configure core.sharedRepository Permissions of Shared Repository
Set the ‘core.sharedRepository’ in the configuration of the repository being set to group. With this setting every new file and folder created inside the repository will automatically be set with group permissions.
git config core.sharedRepository group
This can be set either at the time of cloning this repository by each developer, or on the shared repository itself.
Restrict Group Perms with ‘chmod’ and ‘chown’
Ensure that there is correct group ownership and permission set for the files in the repository. In the repository’s folder execute the following:
sudo chown -R : .git
sudo chmod -R g+rwX .git
The term <shared-group> should be replaced by the group name that is common to all the developers.
Set-GID (Set Group ID) on ‘.git/objects’
This helps to ensure that new files and folders created inside ‘.git/objects’ will have the directory’s group set. As a result, there are no group inconsistencies.
sudo chmod -R g+rwX .git/objects
sudo find .git/objects -type d -exec chmod g+s ‘{}’ +
Simplify and Enforce Permission Using a Hook After Update
Administering permissions issue from individual post push can be resolved by introducing a post update hook. First create a file .git/hooks/post-update with the below content:
#!/bin/sh
chmod -R g+rwX .git/objects
find .git/objects -type d -exec chmod g+s '{}' +
Next issue the command:
chmod +x .git/hooks/post-update
This way when group permissions are setup like this, the files will retain appropriate permissions for each of the developers when they push without the need for changing the default group configuration.