问题
I just created a new git repo on Gitlab.
I init and pushed an already populated directory in the following manner:
git init
git remote add origin git@gitlab.com:username/reponame.git
git add .
git commit -m 'first commit'
git push -u origin master
All worked as expected. However, when I try to pull back from the repo i get
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
This error appears for:
git pull
git fetch
It does not appear for:
git push
Push is working fine, I have made several pushed several changes...
I did initially get my ssh password wrong a few times and attempted at first to push an empty repo.
What is wrong here?
回答1:
Ok so it appears.
Git init generated a FETCH_HEAD file that belonged to root. The rest of .git/ was my users.
I had to change the ownership of the file to my user an then the problem resolved.
Why it was not simply refusing me permission to access the file I do not know.
回答2:
The error you are getting is an SSH error. SSH is used by Git when you use the user@host:path
syntax, but the difference between git pull
and git push
comes after the authentication (and this error). So it's not a matter of push/pull, but it must be the way you call it (e.g. because you called git pull
and git push
from two different terminals with different environment variables set).
Can you run in a terminal:
git pull; git push
?
Actually, since this is only an SSH problem, you can also debug this using ssh itself:
ssh -vvv git@gitlab.com:username/reponame.git
回答3:
I believe an SSH error has occurred. Troubleshoot the following :
- Check that you are actually connecting to the server:
ssh -vT git@github.com
Make sure you have the same key as what's being used:
# start the ssh-agent in the background eval "$(ssh-agent -s)" # Agent pid 59566 ssh-add -l # 2048 a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/you/.ssh/id_rsa (RSA)
- Double check your SSH keys: https://help.github.com/articles/generating-ssh-keys
来源:https://stackoverflow.com/questions/30747634/i-can-push-but-not-pull-git