While executing git pull, it failed: error: cannot open .git/FETCH_HEAD: Permission denied
.
Solution
Add current user to the group of the directory.
[Find the owner of a directory or file]1.
sudo usermod -aG `stat -c '%G' .` $USER
Give the writing permission to the group.
sudo chmod -R g+w .
Follow up
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 2), reused 0 (delta 0)
error: insufficient permission for adding an object to repository database .git/objects
fatal: failed to write object
fatal: unpack-objects failed
After some times of git pull
operations, it occurred as above.
The key point is insufficient permission for adding an object to repository database .git/objects
, that is the current user don't have write permission of the directory.
Assuming that user A is the repo owner, and use B is in the group of user A(, that is group A).
We have add write permission of group to the repo directory.
Now, B has the write permission, but A is not in the group of user B.
So how to resolve the above error?
In my opinion, add user A to the group of user B(, that is group B), and then give the write permission of group to the directory .git/objects
.
sudo usermod -aG `id -g -n` `stat -c '%U'`
sudo chmod -R g+w .git/objects
References
- https://unix.stackexchange.com/a/7732.