I can push but not pull git

孤街醉人 提交于 2020-02-29 04:45:30

问题


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 :

  1. Check that you are actually connecting to the server: ssh -vT git@github.com
  2. 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)
    
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!