问题
Help me please, I am trying to run this in my terminal:
asgard@asgard-A7N8X2-0:~/CollegePortal$ git pull
error: cannot open .git/FETCH_HEAD: Permission denied
Then I try this one
asgard@asgard-A7N8X2-0:~/CollegePortal$ sudo git pull
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Help me, I don't understand this problem.
回答1:
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
回答2:
Check if you have enough permissions on the .git/ directory. You should have write permissions. You can set them with the following command.
Go to your project folder:
chown -R youruser:yourgroup .git/
回答3:
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
回答4:
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.
回答5:
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.
回答6:
In my case work fine after it:
rm -f .git/FETCH_HEAD
回答7:
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/
回答8:
In my case, I only had read access to the .git/FETCH_HEAD file. I had to do "sudo chmod g+w .git/FETCH_HEAD" in order to be able to do a pull request.
回答9:
If you haven't added yourself to the group that owns .git/, then you should.
sudo usermod -a -G $(stat -c '%G' .git) $USER
sudo chmod g+u .git -R
sudo chmod g+u .gitignore
su - $USER
What this does:
- finds out which group owns
.git/and adds your user to that group. - makes sure group members have the same permissions as the owner for
.git/. - repeats this for
.gitignore, which you'll probably need - logs you out and back in to refresh your group membership file permissions
If you just recently did something like this (added yourself to the group that owns .git/), then you need to log out and back in before you'll be able to write to .git/FETCH_HEAD during your git pull.
回答10:
I was having the first issue (FETCH_HEAD permission denied) on Windows.
I fixed it by running Git Bash as an administrator (right click, run as administrator).
回答11:
Set permission to your current user by running the command
$ sudo chown -R <username> .git/
回答12:
Running Windows 7, when I had this issue it was because I had hidden the .git folder. The permissions were fine, it was just hidden. Showing the folder resolved it.
回答13:
This worked for me:
- Right click .git folder
- click get info
- set permission to your user
- click the Cog icon and click apply to enclosed items
No more permission denied errors in git. 🎉
回答14:
Look at the owner and group of .git directory with (first go to parent directory of .git) ll .git , look at the group and owner of the directory,
add your user to group of of the owner with sudo usermod -a -G yourusername groupsofonwner, then logout => login and everything getting work.
So in summeries
go to parent directory of git
$cd your pathfind group owner of the
.gitdirecotry$ll .gitadd your user to that group
$usermod -a -G yourusername ownergroupofgitLogout and login to system to this change take effect.
Enjoy it ;)
回答15:
Got that issue when .git folder is hidden and all files in it is hidden too. Make only .git folder hidden without recursive files update and it will work.
回答16:
Reasons of this error could be multiples but in my case i updated branch with root then when i tried to update it with normal user it gives me error .
try both solutions one should work for you
1- sudo chmod g+w .git -R
if it doesn't work please try next solution hope it will solve your problem
2 - rm -f .git/FETCH_HEAD
回答17:
Simply go to your root folder and run this command:
chmod a+rw .git/FETCH_HEAD
回答18:
I had this message when using git extensions for windows. My fix was to simply close git extensions then open again as administrator
回答19:
In my case,
sudo chmod ug+wx .git -R
this command works.
回答20:
This issue arises when you don't give sufficient permissions to .git folder. To solve this problem-
- First navigate to your working directory.
Enter this command-
sudo chmod a+rw .git -R
Hope it helps..!!
回答21:
This will resolve all permissions in folder
sudo chown -R $(whoami) ./
回答22:
I had the exact same error but in my case, the problem was the result of having rebuilt Apache after an upgrade to the PHP version. Long story short, I forgot to install the Apache module 'suexec'.
It had nothing to do with group or ownership. That only took me two days to figure out, someone shoot me...
回答23:
I got this because I had more than 1 user account on my box. I was logged in as user A and was in a directory for user B. User A didn't have permission to user B's stuff. Once I realized I wasn't where I thought I was in the file system, this error made sense.
回答24:
if you find the same problem in windows server, then you need to run the command line with enough permission, such as administrator permission.
回答25:
In my case I had a dual-boot system (Windows 10 and Linux) with project folder on NTFS disk. It turned out that on another update Windows 10 enabled by itself "fast startup" in its settings. After I've unchecked it in the Windows - the "error: cannot open .git/FETCH_HEAD: Permission denied" in Linux was gone.
来源:https://stackoverflow.com/questions/13195814/trying-to-git-pull-with-error-cannot-open-git-fetch-head-permission-denied