Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+6 votes
2 views
in DevOps and Agile by (19.4k points)
When I try to push to a shared git remote, I get the following error: insufficient permission for adding an object to the repository database.

Then I read about a fix here: Fix This worked for the next push since all of the files were of the correct group, but the next time someone pushed up a change it made a new item in the objects folder that had their default group as the group. The only thing I can think of is to change all of the developer's default group for items they check-in, but that seems like a hack. Any ideas? Thanks.

3 Answers

+6 votes
by (27.5k points)

Perform these commands from the project root,

cd .git/objects

ls -al

sudo chown -R yourname:yourgroup *

You can tell what yourname and yourgroup should be by looking at the permissions on the majority of the output from that ls -al command

Don't miss the asterisk '*' at the end of the sudo line

+6 votes
by (62.9k points)

Repair Permissions

After you have found and fixed the underlying cause see the below code, to repair the permissions:

cd /path/to/repo.git

sudo chgrp -R groupname .

sudo chmod -R g+rwX .

find . -type d -exec chmod g+s '' +

Note if you want everyone to be able to modify the repository, you don't need the chgrp, so you will remove it and you will want to change the chmod to sudo chmod -R a+rwX .

So, if you do not fix the underlying cause, the error will keep coming back and you'll have to keep re-running the above commands over and over again.

Underlying Causes

The error could be caused by one of the following:

  • The repository isn't configured to be a shared repository (see core.sharedRepository in git help config). If the output of:

git config core.sharedRepository

is not group or true or 1 or some mask, try running:

git config core.sharedRepository group

and then re-run the recursive chmod and chgrp (see "Repair Permissions" above).

The OS does not interpret a setgid bit on directories as "all-new files and subdirectories ought to inherit the group owner". When core.sharedRepository is true or group, Git relies on a feature of GNU OSs (e.g., every Linux distribution) to make sure that the newly created subdirectories are owned by the correct

group (the group that each one of the repository's users is in).

This feature is documented within the gnu Coreutils documentation

0 votes
by (1.7k points)

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.

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...