Error while pull from git - insufficient permission for adding an object to repository database .git/objects

Git

Git Problem Overview


I have git error: "insufficient permission for adding an object to repository database .git/objects" every time I make "git pull origin develop".

    remote: Counting objects: 70, done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 42 (delta 35), reused 42 (delta 35)
    error: insufficient permission for adding an object to repository database     .git/objects

    fatal: failed to write object
    fatal: unpack-objects failed

Git Solutions


Solution 1 - Git

Assuming @ChrisHayes is right about an accidental sudo, this should fix it. From inside your repository:

sudo chown -R $USER:$USER "$(git rev-parse --show-toplevel)/.git"

Update: for those of you getting the illegal group name error, try this instead:

sudo chown -R $(id -u):$(id -g) "$(git rev-parse --show-toplevel)/.git"

Solution 2 - Git

Go to project's root directory and run below commands to fix this issue,

cd .git/objects
sudo chown -R yourname:yourgroup *

Solution 3 - Git

Mine was a stupid mistake... the right username and group were set, but www-data was the account accessing it. The directory was owned by vaindil:www-data, but permissions were 755 so www-data couldn't write to it. Fixed it with:

$ sudo chmod -R 775 /path/to/repo

Solution 4 - Git

NOT A GOOD PRACTICE (Just an alternative)

I am using Ubuntu and faced the same problem. To solve it, I simply switched user to root and I see no further error.

$su
password

Then,

$git pull origin master

Recommended way: CHANGE THE PERMISSION OF THE DIRECTORY

Solution 5 - Git

remove .git from the url, if you are trying to clone a public repository from github.

example:

From: https://github.com/example/repository.git To: https://github.com/example/repository

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionunnati patilView Question on Stackoverflow
Solution 1 - GitdwurfView Answer on Stackoverflow
Solution 2 - GitPriyank PatelView Answer on Stackoverflow
Solution 3 - GitvaindilView Answer on Stackoverflow
Solution 4 - GitNabinView Answer on Stackoverflow
Solution 5 - GitGaurav AroraView Answer on Stackoverflow