! [remote rejected] master -> master (unpacker error) Fix

Today, when pushing to a Git server I had set up myself, I ran into this error:

remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To git@127.0.0.1:/srv/git-server/checkpoint.git
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'git@127.0.0.1:/srv/git-server/checkpoint.git'

At first, I could not find a suitable solution on Google. In the end, I discovered that I had made a permissions mistake when initializing the repository.

After creating the bare repository, you need to change the owner of the repository directory and all files inside it to the Git user. When I ran chown, I had missed the -R option, so the files under the directory did not have their owner changed recursively. As a result, Git failed with insufficient permissions when writing objects.

The fix is as follows:

sudo chown -R git:git repositoryname.git

If the repository path is /srv/git-server/checkpoint.git, you can run:

sudo chown -R git:git /srv/git-server/checkpoint.git

Then push again.

You can also check the current permissions first:

ls -la /srv/git-server/checkpoint.git
ls -la /srv/git-server/checkpoint.git/objects

Confirm that both the repository directory and the objects directory are owned by git:git.

Leave a Reply