Nisarg
Nisarg

Reputation: 3252

Git : fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists

I am getting this error -

D:\Projects\wamp\www\REPO [master]> git pull origin master
Warning: Permanently added 'github.com,192.30.252.128' (RSA) to the list of known hosts.
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

The output of git remote -v

D:\Projects\wamp\www\REPO [master]> git remote -v
origin  [email protected]:username/repo.git (fetch)
origin  [email protected]:username/repo.git (push)

Final message of ssh -Tv [email protected] command -

Hi [My Username]! You've successfully authenticated, but GitHub does not provide shell access.

How can I solve it?

Upvotes: 137

Views: 605467

Answers (26)

S.V
S.V

Reputation: 2793

If one creates a new local git repository and then attempts to push it to GitHub, GitHub will not create a new repository automatically. One has to create a new repository on GitHub manually before one could push into it. That is another reason one could get the error:

ERROR: Repository not found.
fatal: Could not read from remote repository.

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

Upvotes: 0

Hernando N
Hernando N

Reputation: 305

When I created new projects on GitHub.com, the default option for connecting to the repository was SSH Key.

I was copying the link that starts with [email protected]:<username>... and tried to clone the repo with this link.

I had to change to the HTTPS tab and copy the url that starts with https://github.com/<username>/... to use the git clone command.

Upvotes: 0

IvanKD
IvanKD

Reputation: 1

I was getting this error when I tried to clone from my organization repository (my server ssh key was added to my github account and I could clone from my personal repos, but could not clone from organization).

I set up the server with Laravel Forge. During set up, Laravel Forge creates Laravel Forge Application in Applications on GitHub (in the Authorized OAuth Apps tab). But this app does not get access to your organizations by default.

The solution to this error was to grant access for Laravel Forge Application to my organization in GitHub using GitHub interface. Open you applications here https://github.com/settings/installations, the go to "Authorized OAuth Apps" tab, then choose "Laravel Forge" app, then press the "Grant" button for the needed organization (see pictures).

This was not obvios to me at first, because I thought that the Forge app has access to all repos by default, including organization repos.

Applications

Laravel Forge Authorized OAuth App Grant buttons

Upvotes: 0

emovere
emovere

Reputation: 162

Easy solution for me:

  1. The public SSH Key has to be saved on https://github.com/settings/keys

  2. The email address inside "~/.ssh/id_rsa.pub" (At the end of the file) has to be entered on Github (https://github.com/settings/emails). (This was my problem)

After I saved the email address on GitHub, the problem solved itself.

Upvotes: 3

Tan Nguyen
Tan Nguyen

Reputation: 1091

I faced the same issue because I have a lot of Git accounts, you can resolve this issue by instructions below:

For macOS

eval `ssh-agent -s`
ssh-add --apple-use-keychain ~/.ssh/your_key.pub

For Linux

eval `ssh-agent -s`
ssh-add ~/.ssh/your_key.pub

Upvotes: 0

I needed to have rw for user only permissions on config. This fixed it.

chmod 600 ~/.ssh/config

Upvotes: 2

Austin Heller
Austin Heller

Reputation: 320

I had this same issue and resolved it by adding my SSH key in the ~/.ssh/config file and then updating my git repo url.

~/.ssh/config:

Host github.com-repo-0
    Hostname github.com
    IdentityFile=/home/user/.ssh/repo-0_deploy_key

git repo url:

$ git remote set-url origin [email protected]:OWNER/repo-1.git

Note that the Host text exists between the @ and : symbols in the git url.

Source: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys

Upvotes: 0

Nidhin David
Nidhin David

Reputation: 2474

For me somehow sudo rebooting the fluffing EC2 instance after a fresh ssh-keygen and rm ~/.ssh/known_hosts fixed it! Still not sure how it works but it worked on 4 different EC2 servers with uptime over 700 days. I think it is related to some breaking updates on some processes during the 700 days!! Still not sure what fixed it but for damn its fixed!

Upvotes: 0

Shashank Ks
Shashank Ks

Reputation: 690

For me, I was getting this error because my ssh agent was not running somehow. Doing this worked:

eval `ssh-agent -s`
ssh-add path_to_your_key

Upvotes: 50

BZKN
BZKN

Reputation: 1709

I had the same problem. I tried a couple of solutions mentioned above, it did not work for me. I even restarted my machine and also reconnected my WLAN. But all in vain. Then on the remote repo, I manually made a small change in the readme file of the repo. To pull that change on the local copy of my repo in my machine, I did the usual git pull and then the git push origin. This actually worked.

Upvotes: 0

Nafees
Nafees

Reputation: 1034

Its not necessary to apply above solutions, I simply changed my internet, it was working fine with my home internet but after 3 to 4 hours my friend suggest me to connect with different internet then I did data package and connect my laptop with it, now it is working fine.

Upvotes: 0

Jonathan Perry
Jonathan Perry

Reputation: 3043

For me none of the solutions here solved it. Frustrated, I restarted my Macbook's iTerm terminal, and voila! My github authorization started working again.

Weird, but maybe iTerm has its own way of handling SSH authorizations or that my terminal session wasn't authorized somehow.

Upvotes: 3

Tudor
Tudor

Reputation: 1578

ssh-add -D  # Delete all identities.
ssh-add ~/.ssh/your_key

Edit 1
Since I get so many votes, I discovered some issue with this approach and that is that it will remove all your identities so you might have the same issue when you try to read from other repositories and you will need to to this step again for each project...but it might also not be the case for your project

Upvotes: 8

Steve Bauman
Steve Bauman

Reputation: 8668

Strangely I had this occur with a single repository out of > 20 repositories on my MacBook Pro.

The solution was to upgrade git via homebrew, and everything strangely worked after it finished:

brew install git

Hope this helps someone!

Upvotes: 0

laimison
laimison

Reputation: 1698

This issue could be related with missing SSH key at Github or any other git server.

In my case I had copied code to another computer and tried to git pull. It failed.

So I had to generate a new SSH key on that machine and update profile on git server with additional SSH key.

Upvotes: 0

Manic Depression
Manic Depression

Reputation: 1030

In my case updating GIT helps - I had version 2.23 and with installing version 2.26.2.windows.1 problem disapears.

So if you are sure your SSH key is valid then (see @VonC answer):

  1. update GIT
  2. update composer
  3. run composer clearcache

And it should be ok.

Upvotes: 1

Krishna Bagale
Krishna Bagale

Reputation: 51

Try:

git config --global credential.helper cache

This command prevents git to ask username and password, not forever but with a default limit to 15 minutes.

git config --global credential.helper 'cache --timeout=3600'

This moves the default limit to 1 hour.

Upvotes: 3

Maybe, as in my silly situation, you may somehow created the ssh key by directly typing

ssh-keygen

And so it is created with the local system user credentials so they don't match, use full command like this and recreate

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Upvotes: 2

BSB
BSB

Reputation: 2468

This error can be because of no SSH key on the your local machine. Check the SSH key locally:

$ cat ~/.ssh/id_rsa.pub

If above command do not give any output use below command to create ssh key(Linux/Mac):

$ ssh-keygen 

Now again run cat ~/.ssh/id_rsa.pub This is your SSH key. Copy and add this key to your SSH keys in on git. In gitlab/bitbucket go to

profile settings -> SSH Keys -> add Key

and add the key

Upvotes: 10

otoloye
otoloye

Reputation: 697

I had this issue and tried many things but still din't work. Eventually I decided to generate another SSH KEY and boom - it worked. Follow this article by github to guide you on how to generate your SSH KEY.

Lastly don't forget to add it to your github settings. Click here for a guide on how to add your SSH KEY to your github account.

Upvotes: 1

Muhan Alim
Muhan Alim

Reputation: 489

This error happened to me too as the original repository creator had left the company, which meant their account was deleted from the github team.

git remote set-url origin https://github.com/<user_name>/<repo_name>.git

And then git pull origin develop or whatever git command you wanted to execute should prompt you for a login and continue as normal.

Upvotes: 12

Jaime Agudo
Jaime Agudo

Reputation: 8286

Sometimes that (copying the pub ssh key to github/bitbucket) is not enough, particularly with Bitbucket. You also may need to check if your ssh is using the identity you expect rather than messing up with git remote

Check if the agent is using the same identity you pasted on github/bitbucket with ssh-add -l. If missing add it with

ssh-add ~/.ssh/id_rsa_my_git_identity

Further details: https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html

Upvotes: 17

Siyaram Malav
Siyaram Malav

Reputation: 4688

change your ssh url by an http url for your remote 'origin', use:

> git remote set-url origin https://github.com/<user_name>/<repo_name>.git

It will ask for your GitHub password on the git push.

Upvotes: 125

Saurabh Kumar
Saurabh Kumar

Reputation: 2367

I got the very same errors too. In My case upgrading from Windows 7 to 8 messed up my settings. What helped was to regenerate the private and public SSH keys using PuTTYGen, and change the SSH tool in tortoisegit from SSH to Plink.

I have shared the step by step steps also at http://techblog.saurabhkumar.com/2015/09/using-tortoisegit-on-windows-with.html

Upvotes: 2

kip2
kip2

Reputation: 6863

Sometimes this happens to me because of network problems. I don't understand the problem fully, but switching to a different sub-network or using VPN solves it

Upvotes: 10

VonC
VonC

Reputation: 1323115

I asked in the discussion:

does ssh -T [email protected] ouput the same username (in Hi [My Username]!) as in the one used for the ssh url of your repo ([email protected]:username/repo.git)?

Sorry It not showing same name

That means somehow the credentials have changed.

One solution would be to at least copy %HOME%\.ssh\id_rsa.pub in the SSH keys section of the right GitHub account

The OP adds:

I am working on private repo. So In [email protected]:username/repo.git,

I replied:

If you were able to clone/push to that repo whose username is not your own GitHub account, that must be because you had your previous public ssh key added as a contributor to that repo by the repo's owner.

What next is to ask that same repo owner to add your current public ssh key %HOME%\.ssh\id_rsa.pub to the repo contributor list.
So check with the owner that you (meaning your public ssh key) are declared as a contributor.

Upvotes: 34

Related Questions