Search code examples
gitgithubsshmacos-sierragit-push

git push failed in MacOS Sierra 10.12.5


Recently I tried to use git in MacBook Pro with Sierra 10.12.5. The git was using without complaint in Mavericks, however, it gives problem in git push now.

Note

There are literally a number of similar and same problem in SO and google, but none of them worked for me.
If anybody suggests a link that solves my problem I will happily remove my question, no need to downvote, this problem is taking a lot of time for me.

This seems to be a stupid problem, just not being able to push to git hub repo, but admit it nor not, this is the problem that is bothering me in the mean time.

Thanks for your help, if you can help.

Error:

ERROR: Permission to XXX.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Things Done So Far:

  1. Copied contents of ~/.ssh/id_rsa.pub to GITHUB/Settings/SSH and GPG keys/ New Key

  2. Testing

    ssh -T [email protected]

Gives:

Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
  1. Then I cloned a practice repo from my GitHub account:

    git clone [email protected]:bhishan2/practice.git.
    cd practice.
    touch example.txt.
    git add example.txt.
    git commit -m "added a file"
    git push origin master.

Now I got the above error.

How can we solve this error?

Related links:
git: fatal: Could not read from remote repository
https://community.atlassian.com/t5/Bitbucket-questions/git-pull-fatal-Could-not-read-from-remote-repository/qaq-p/122111
https://github.com/jakubroztocil/cloudtunes/issues/23

Help will be truly appreciated.


Solution

  • Last time I saw that error after a successful ssh -T github.com was in 2015

    And the Hi USERNAME was not exactly the same as the intended GitHub account (here bhishan2)

    That means the cloned repo bhishan2/practice can be cloned, but cannot be pushed to, because the ssh key authenticates as the wrong owner.