08.21.2019

Git fetch, git pull or git push error

Error while pull from git - insufficient permission for adding an object to repository database .git/objects
fatal: failed to write object
fatal: unpack-objects failed

Problem

I deployed my ruby on rails project on amazon vps used capistrano and puma.
I used git on my production server with ssh key and bitbucket.
Some days ago everything worked well. But today when I run
cap production deploy
Source code did not updated. Then I try to use command to fetch and pull new source code into my server. but it return error
Error while pull from git - insufficient permission for adding an object to repository database .git/objects
fatal: failed to write object
fatal: unpack-objects failed

Solution

I searched for this bug and I got solution from stackoverflow.
Firtly, I had tried these command 
cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

but the problem was not fixed
Then I try this command
sudo chown -R $USER:$USER "$(git rev-parse --show-toplevel)/.git"
Then the problem was solved.

Leave a comment