How to fix git 'error: cannot open .git/FETCH_HEAD: Permission denied'

Problem:

You want to run git pull or some other git command but you only see this error message:

error: cannot open .git/FETCH_HEAD: Permission denied

Solution

This means that the .git directory is not owned by you. The easiest way to fix that is to change the owner of the directory to your user.

First, go to the root directory of the repository using cd, if you are not already there.

Then,

sudo chown -R $USER: .

In case you don’t have sudo access on that computer, the easiest way is to copy the repository to a directory where you have write access (e.g. using cp -r) or even clone the repository again.