Git gives 'ERROR: Repository not found.' when URL is correct and SSH key is used

I had a fun problem that made me spin my wheels an hour or so today. I was having no issue cloning a remote repository a number of times in the morning while debugging a Jenkins build job that runs a git clone + Docker image build and push operation.

Suddenly, when I was doing some final testing, I started to get the following:

git clone [email protected]:geerlingguy/my-project.git                            
Cloning into 'my-project'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

I know that I had the repository's SSH key loaded (via eval "$(ssh-agent -s)" && ssh-add ~/.ssh/deploy-key), and if I unloaded the key, I would instead get:

Permission denied (publickey).
fatal: Could not read from remote repository.

...but after doing test after test, and confirming I could access GitHub itself just fine with ssh -T [email protected], I began to wonder if I was delusional. I went back to the GitHub repo's GitHub page, and copied and pasted the URL using both HTTPS and SSH endpoints, and kept hitting the same issue.

Then I realized that this particular project was able to be run for a variety of different codebases, each one with it's own deploy key (GitHub requires a universally unique deploy key for each usage). And my local environment had the wrong codebase deploy key loaded. D'oh! I replaced the key in ~/.ssh/deploy-key with the correct one, and now I am able to git clone without an issue.

I wouldn't have posted this blog post but for the fact that 99.9% of all the other "Repository not found" posts in Google search said "check your repository URL". Well, this blog post points out another way you can run into the issue, even if the repo URL is correct.

Comments

Hi Jeff,
I have similar problem with my computer , URL and ssh keys are correct. I can fetch and pull from repo but when I push code it gives me error
exec request failed on channel 0
fatal: Could not read from remote repository.
It works on other machines.
Please make sure you have the correct access rights. Any pointers?

I found there were a number of reasons why this fatal error might occur, not just SSH releated.

* You did not authenticate
* Your password has changed
* You are not a collaborator
* Incorrect case or a word misspelled
* The git repository has been deleted

One of these reasons might be the cause of the same problem. I blogged about it if anyone is interested:

https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Op…

Yup - same problem here of everyone saying set the url, which was obviously already done. My issue came up when Github changed their host keys and I kept getting an annoying message that the ip address for the new key didn't match the old one. So, after `ssh-keygen -R ` I stopped getting that annoying message but, because I'm dumb and didn't read any documentation before running the voodoo, it removed my key from the ssh agent (like it's supposed to) without me realizing it. Thanks for taking the time to post!