dmz73
dmz73

Reputation: 1608

Git commit fails due to insufficient permissions

I am getting the following error while trying to commit to a local repository:

error: insufficient permission for adding an object to repository database .git/objects

I created another repository to compare the permissions of .git and .git/objects and everything works fine in the new repository, and the permissions are the same drwxr-xr-x.

What might be causing this error?

Upvotes: 10

Views: 8713

Answers (3)

Sebastián Lozada
Sebastián Lozada

Reputation: 101

cd <path-to-repo>
cd .git/objects
sudo chown -R <username>:<group> *

This worked for me with group staff.

Upvotes: 4

Dineshkumar
Dineshkumar

Reputation: 1

I have faced the same issue. I thought my current working local repository got corrupted. So I have cloned the repository from remote again. Now I'm able to do commit and push from this new repository without any issues.

Note: If you want your old repo changes then use git stash and do git stash apply in new repo.

Upvotes: 0

andrej
andrej

Reputation: 4743

cd repository
chown -R user:group *
cd .git
chown -R user:group *
cd ..

the second chown is there because the first one didn't get into .git

Edit: If above does not help, try to run the chown commands as root.

Edit 2: replace 'user' and 'group' with your username and groupname.

Upvotes: 13

Related Questions