143

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
unnati patil
  • 1,601
  • 2
  • 13
  • 12

5 Answers5

319

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"
dwurf
  • 12,393
  • 6
  • 30
  • 42
  • 9
    What does `git rev-parse --show-toplevel` do? I was able to fix the issue just by using `chown -R user:user` on the top-level directory of my repo. – Matt K May 12 '14 at 14:29
  • 15
    @MattK this will get the top-level directory of your repo, so the command will work regardless of where in your repo you currently are. If you're already in the root you can just run `sudo chown -R $USER:$USER .git` – dwurf May 29 '14 at 02:31
  • I get: `Sorry, user myuser is not allowed to execute '/bin/chown' ...` – Francisco Corrales Morales Jul 17 '14 at 15:18
  • 7
    I get: `illegal group name` – Ian Aug 01 '14 at 17:03
  • 1
    I was using the wrong username. The command worked. Thank you. – Ian Aug 01 '14 at 17:12
  • 1
    it also happened to me after an accidental sudo before. changing the owner/group fixed it – Asped Dec 17 '15 at 10:33
  • I am a little late to the party here, but I tried executing the second option above after getting the Operation not permitted for the first option and 'rev' was not a valid command, try revert. Tried revert and I received a fatal: bad revision 'parse' and chown: invalid option -- '1'. Also where you have $(id -u):$(id -g) am I typing anything unique to my own repo? I am fairly new to this. – Jack Armstrong Apr 16 '20 at 23:52
  • @Jack Armstrong It sounds like you may have typed `rev -parse` with a space. The correct command is `rev-parse` (no space) – dwurf Apr 18 '20 at 00:18
27

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

cd .git/objects
sudo chown -R yourname:yourgroup *
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85
3

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
vaindil
  • 7,536
  • 21
  • 68
  • 127
0

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

Nabin
  • 11,216
  • 8
  • 63
  • 98
0

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

Blue
  • 22,608
  • 7
  • 62
  • 92