Advertisement
Advertisement


Trying to git pull with error: cannot open .git/FETCH_HEAD: Permission denied


Question

Help me please, I am trying to run this in my terminal:

[email protected]:~/CollegePortal$ git pull
error: cannot open .git/FETCH_HEAD: Permission denied

Then I try this one

[email protected]:~/CollegePortal$ sudo git pull
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Help me, I don't understand this problem.

2017/10/04
1
212
10/4/2017 12:34:27 PM

Accepted Answer

It seems like the first one isn't working because your user doesn't have the permissions for changing that directory, and the second because your root user doesn't have the right SSH keys for accessing that git repository.

Depending on what you're trying to do, it might be better to clone the repository to a different directory, or maybe chown the current directory to have full access for your user

2012/11/02
197
11/2/2012 1:09:09 PM


If you want to give the permission to the group,

sudo chmod g+w .git -R

worked best for me.

For MacOS

sudo chmod -R g+w .git 
2018/11/08

This is a UNIX permission problem. Do not use sudo for cloning the repository. You don't have the same ssh keys as root and you shouldn't work as root anyway. Try ls -la to find the permissions on the files and use chmod (or sudo chown) to fix them. Hope that helps.

2020/02/22

In my case work fine after it:

rm -f .git/FETCH_HEAD

git branch -u
2020/03/03

The answer to this issue make sure .git/FETCH_HEAD has write privileges and you will be all set.

I had this issue on Windows and it was resolved by giving write permissions.

In unix one can run chmod a+rw .git/FETCH_HEAD from the project repository after which it should work.

2015/03/07

Try like this way,

Step 1: First check who you are? it will return current user name e.g ubuntu

$ whoami 

Step 2: Then set permission to your current user, in that case, ubuntu by

sudo chown -R ubuntu .git/
2018/05/15