I can push but not pull git

2.7k views Asked by At

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 [email protected]: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?

3

There are 3 answers

0
tanbog On BEST ANSWER

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.

0
Matthieu Moy On

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 [email protected]:username/reponame.git
0
jojo On

I believe an SSH error has occurred. Troubleshoot the following :

  1. Check that you are actually connecting to the server: ssh -vT [email protected]
  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