≡ Menu

How to Fix Git Push Insufficient Permission Error for Objects Permanently

Sometimes when you do a git push, you might get the following permission error message.

This error typically happens when multiple users are working on a particular git repository.

The following git push error indicates that it doesn’t have enough permission for adding a new object to the ./objects directory under your repository.

Apart from the obvious permission issue, there is also another underlying problem that needs to be addressed, which is explained in this tutorial.

$ git push
counting objects: 6, done.
Delta compression using upto 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 388 bytes, | 0 bytes/s, done.
Total: 4 (delta 1), reused 0 (delta 0)

error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
 ! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to john@192.168.100.1:/home/git/myproj

It also shows that the git unpack failed with unpack-objects abnormal exit. Because of this error, it failed to push some refs as shown above.

First, cd to the git repository which is having this issue. If you don’t see the objects directory directly under your repository folder, then look under the .git folder as shown below.

[john@devdb]$ cd /home/git/myproj
(or)
[john@devdb]$ cd /home/git/myproj/.git

In this particular case, when john is trying to do ‘git push’, he is getting the above error because some of the directories under the objects folder of git repository are owned by lisa as shown below.

[john@devdb]$ ls -l objects
drwxr-xr-x 2 john  git 4096 Oct  8  2016 01
drwxr-xr-x 2 john  git 4096 Oct  8  2016 02
drwxr-xr-x 2 lisa lisa 4096 Oct  8  2016 03
drwxr-xr-x 2 lisa lisa 4096 May  1  2017 04
drwxr-xr-x 2 john  git 4096 May  1  2017 05
drwxr-xr-x 2 john  git 4096 May  6  2017 06

Set the Appropriate Permissions on Objects Directory

To solve this problem, execute the following, which will set the group to git (or whatever group where all the users belongs to. Also make sure the user and group has read and write permission to the directory.

cd /your/git/repo

chgrp -R git objects

chmod -R g+rws objects

In the above:

  • Make sure all your users who need access to git are part of the git group. Change the “git” in the above chgrp command to whatever group where all your developers belong to.
  • The “s” option in the “g+rws” is to set the setuid bit on the objects folder. This will make sure any new directory created under objects folder will make the group name from the objects folder which is owned by git group.

You may be tempted to execute the following on your objects directory, which will solve the problem that you are having. But, as you can imagine, it is not a good idea to do 777. Instead execute the above chgrp and chmod command.

chmod -R 777 objects

Share the Git Repository with a Group

But, even after doing the above, the same problem might return again, and you may have to do the above chgrp and chmod whenever the problem occurs.

So, apart from fixing the permission error as explained above, we also need to fix the underlying problem.

In this case, the git repository (for example: myproj) is not setup as shared repository for groups. It might just be a bare repository.

If it is not setup as shared repository, you’ll see the above “insufficient permission on objects directory” issue starts to show-up again.

To verify whether your repository is already setup for group sharing, do the following git config -l option inside your git repository that has the problem.

$ cd /home/git/myproj

$ git config -l
user.name=John Smith
user.email=john@thegeekstuff.com
core.repositoryformatversion=0
core.filemode=true
core.bare=true
core.logallrefupdates=true

In the above output, we don’t see a parameter called “core.sharedrepository”. So, this particular repository (i.e myproj is not setup as shared repository).

The above command displays the configuration values from the “config” file that is located under your git repository.

$ cd /your/git/repo

$ cat config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        logallrefupdates = true

The above is setup as a bare repository. To convert a bare repository to shared repository, do the following:

git config core.sharedRepository group

Note: In the above command, don’t replace the keyword “group” with your groupname (for example: git). Use the above above command exactly as shown without changing anything. The “group” in the above command should be typed exactly as it is.

Now, if you view the git config as shown below, you’ll see the “core.sharedrepository” parameter set to group.

$ git config -l
user.name=John Smith
user.email=john@thegeekstuff.com
core.repositoryformatversion=0
core.filemode=true
core.bare=true
core.logallrefupdates=true
core.sharedrepository=group

The above will solve the insufficient permission issue permanently.

After you set the sharedrepository, if you view the config file under your git repository, you’ll notice that the value of sharedrepository parameter is set to 2 (which is group) as shown below.

$ cat config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        sharedrepository = 2
[receive]
        denyNonFastforwards = true

Also, anytime you make a git repository as sharedrepository for group using the above command, it will also set the receive.denyNonFastforwards to true automatically as shown above.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Anonymous May 17, 2017, 1:47 am

    Or maybe have the repository accessible via ssh with one user for the repo and the key from each contributor in ~/.ssh/authorized_keys?