Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error pushing to GitHub - insufficient permission for adding an object to repository database

Tags:

git

github

When you see this error outside of github, here's a remedy.

Got this from: http://mapopa.blogspot.com/2009/10/git-insufficient-permission-for-adding.html

ssh me@myserver
cd repository/.git

sudo chmod -R g+ws *
sudo chgrp -R mygroup *

git config core.sharedRepository true

After this the git daemon should use the group file permissions when writing to .git/objects.


Usually this problem is caused by wrong user and group permissions on your Git servers file-system. The git repository has to be owned by the user and also his group.

Example:

If your user is called "git", his group "gitgroup", and the location of the Git repo is: [email protected]:path/to/repo.git

then do a:

sudo chown -R git:gitgroup path/to/repo.git/

This fixed the git insufficient permission error for me.


sudo chmod 777 -R .git/objects

This happened to me when I tried to git pull. Some analysis showed that somebody had commited with root in the past, thereby creating some objects with root ownership in .git/objects.

So I ran

cd <repo>
la .git/objects/

and that showed root ownership for some objects (directories) like this:

user@host:/repo> la .git/objects/
total 540
drwxr-xr-x 135 user user 4096 Jun 16 16:29 .
drwxr-xr-x   8 user user 4096 Jun 16 16:33 ..
drwxr-xr-x   2 user user 4096 Mar  1 17:28 01
drwxr-xr-x   2 user user 4096 Mar  1 17:28 02
drwxr-xr-x   2 user user 4096 Jun 16 16:27 03
drwxr-xr-x   2 user user 4096 Mar  3 13:22 04
drwxr-xr-x   2 root root 4096 Jun 16 16:29 05
drwxr-xr-x   2 user user 4096 Jun 16 16:28 07
drwxr-xr-x   2 root root 4096 Jun 16 16:29 08

Then I ran

sudo chown -R user:user .git/objects/

and it worked!

I was replacing user with my real user, of course.


Nothing of the above worked for me. A couple of hours later I found the reason for the problem: I used a repo url of the type

ssh://[email protected]/~git/repo.git

Unfortunately I stored a putty session with the name example.com which was configured to login as user myOtherUser.

So, while I thought git connects to the host example.com with the User 'git', Git/TortoiseGit has connected to the putty session example.com which uses the User myOtherUser. This leads to the exact same ..insufficient permission.. error (cause both users are in different groups).

Solution: Rename the putty session example.com to [email protected]