How to Fix GIT PUSH ERROR: insufficient permission for adding an object to repository database .git/objects



I use git for all my projects and I have an on-premise git server in my company. This git is hosted on a Linux server. All developpers have a user account on this Linux machine attached to the developers group. My Jenkins server for CI/CD also has its own account on this Linux.

My problem occurs when I make a Maven Release which tags source code on git, upadte project version on my pom.xml file and push it on git. I often have write permission issue.

Let's do a small disgnostic. I open an ssh terminal on my git Linux with Jenkins account. I nagivate to a repository (a /opt/git/ subfolder - depending on your installation). Let's create a dummy file and check its ACL.

cd /opt/git/my-project.git
touch test
ls -lisa test
-rw-r--r-- 1 jenkins developers 34618 june. 23  2020 test

We can see that only the owner can modify this file. Other uiers from the developers group could only read it. That's the problerm : we have to set default ACL on this folder.

Okay, let's do this. We will fix ACL on all repositories :

setfacl -R -d -m g::rwx /opt/git

And then perform a small check on everything :

cd /opt/git
for d in *.git; do ( cd $d && pwd && git fsck && git gc ) done

That's all!