Justin
Justin

Reputation: 45390

Git Push ERROR: Repository not found

I am having a very strange problem with git and github. When I try and push, I am getting:

git push -u origin master
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

I added the remote:

git remote add origin [email protected]:account-name/repo-name.git

Any ideas?

Upvotes: 686

Views: 1208236

Answers (30)

Michel K
Michel K

Reputation: 711

Even with so many answers there's another potential issue and solution:

In my case i'm using a devContainer and have logged in to VS Code with Github. However this is not sufficient. You need to use a personal access token and follow this specific part about the github CLI

https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git#github-cli

log in with personal token and NOT with browser.

You can create the token through settings of your own account -> developer settings -> personal access token -> finegrained

Paste that in the CLI. Reopen the devContainer and it should work :)

Upvotes: 1

Promise Preston
Promise Preston

Reputation: 29068

Had this same issue when working on a MacBook Pro.

When I try to clone or push to a repository, I get the error below:

git clone https://github.com/mytech/mytech_frontend.git

Cloning into 'mytech_frontend'...
remote: Repository not found.
fatal: repository 'https://github.com/mytech/mytech_frontend.git/' not found

This often happens if the computer already has github.com credentials configured in the CLI for another user.

Here's how I solved it:

For Git Clone

First, be sure you have access to the repository either as:

  • a member of the organization in which the repository resides OR
  • a collaborator of the repository

Next, clone the repository using:

git clone https://github.com/path_to/my-repo.git

if you have an existing GitHub account on the computer/terminal, when you try to clone from a repository with another GitHub account you will encounter the same error, so you need to modify your git clone command to:

git clone https://my-username:'personal-access-token'@github.com/path_to/my-repo.git

Example:

git clone https://promisepreston:'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'@github.com/promisepreston/my-writings.git

For Git Push

List the existing repo remote location:

git remote -v 

Output:

origin  https://github.com/my-username/my-repo.git (fetch)
origin  https://github.com/my-username/my-repo.git (push)

Remove the existing remote location:

git remote remove origin

Add the repo remote location again using this pattern:

git remote add origin https://my-username:'personal-access-token'@github.com/path_to/my-repo.git

Example:

git remote add origin https://promisepreston:'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'@github.com/promisepreston/my-writings.git

Upvotes: 4

krishnaacharyaa
krishnaacharyaa

Reputation: 25090

Github removed use of username and passwordon August 13, 2021. Now uses personal tokens instead

To overcome that generate a personal token using create personal token. And use the following snippets to achieve push and clone functionalities

To Push

git remote remove origin
git remote add origin https://[USER]:[TOKEN]@github.com/[USER]/[REPO]
git push

To Clone

git clone https://[USER]:[TOKEN]@github.com/[USER]/[REPO]

Upvotes: 29

Johnny Johnny
Johnny Johnny

Reputation: 29

This SOLVED the problem:

  1. Check your link has correct spelling, you can copy on Github enter image description here

  2. If you're correct all the spelling, maybe your Credential Remote is the issue. Go to Control panel > User Accounts > Credential Manager > Windows Credentials. Find git:https://github.com and click Remove. enter image description here

Make sure you come to git:https://github.com not the other *..github.com enter image description here

Then, now you can do git clone or push or any with your repo. It worked for me!

Upvotes: 1

Dr.Simplisist
Dr.Simplisist

Reputation: 925

I faced this error when I was trying to push to a private repo that I had access to before. The problem was not whether the repo is private or public, the issue is that the Github API uses personal tokens instead of username and password for authentication and authorization now.

The following solved my problem:

  1. remove the remote origin: git remote remove origin

  2. Generate a personal token: you can find the instructions in Github Docs.

  3. Re-add the origin but with your username and the generated token:

git remote add origin https://USERNAME:[email protected]/username/reponame.git

N.B. If you encounter this issue a while after creating and using your token, make sure the token is not expired. If it is, regenerate it and make sure to repeat step 3 (mentioned above) for the repos that used the old token. Also, if you changed your token, redo step 3 for the repos that used the old token.

Upvotes: 75

moyoteg
moyoteg

Reputation: 357

If you have 2 TWO(or more) GitHub accounts:

you will run into issue:

"key already in use" for the same computer

Solution:

  1. create a new key per each organization/account/email

    $ sudo ssh-keygen -t ecdsa -b 521 -C "[email protected]"

  2. add identity

    $ ssh-add ~/.ssh/"whatever key you created"

make sure to add all the "identities" or ssh keys which tells git which keys to try to use when authenticating with GitHub under all organizations.

Upvotes: 1

Nasir Aliyev
Nasir Aliyev

Reputation: 126

In my case it was because of that I added the same SSH key in another GitHub account also. Steps to check and fix

  1. Check it: ssh -T [email protected]. If it shows the correct username then the issue is different. If it is another account then do step 2.
  2. Simply go to another account and delete ssh keys from there.
  3. Use different keys for different accounts. Github really mix up them.

Upvotes: 5

Cels
Cels

Reputation: 1334

If you had everything automated by vscode before and now it's no longer working, Try signing out of your connected github account on vscode and signing back in to the right github account that has access to that repository.

Here is where you sign out and sign back in.

enter image description here

Upvotes: 1

v_for_vantouza
v_for_vantouza

Reputation: 33

For me, none of these replies were useful. I had just forgotten to create the repo on the remote (on github.com). So I created my repo online, using the same name, and then re-done

So, here is the whole story:

git init ...
git add ...
git commit ...
git remote add origin [email protected]:<myName>/<myRepo>.git
git push -u origin main

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

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

--> Here you need to add your repo on github.com with the same "myRepo" name

git push -u origin main 

Upvotes: -1

kangkyu
kangkyu

Reputation: 6130

eval "$(ssh-agent -s)"

It was my own repo - there should be enough access. For other repos I was able to pull & push with no problem. It was solved by starting ssh-agent over again. I use macos.

Upvotes: 4

odunayo12
odunayo12

Reputation: 585

I tried all options, but nothing seemed to work. Further research revealed the following:

  1. Here is a comprehensive approach to solving the problem.
  2. When you get to 5. Fix 4, note that VS code will ask for authentication.

If you enter your password and still get an authentication error, do the following.

  1. Head over to your GitHub menu do Settings -> Developer Settings -> Personal access tokens -> Generate new token. And ensure the boxes are checked according to the picture below. Generate an access token and save it somewhere accessible. enter image description here
  2. Use the generated token instead of the password.
  3. Then continue to step 6. Fix 5

These steps should fix the problem afterwards.

Upvotes: 0

king
king

Reputation: 302

If you are sure you already have SSH access to this repository.

Do

git clone https://[email protected]/path_to/myRepo.git

Upvotes: 4

Marian Kl&#252;hspies
Marian Kl&#252;hspies

Reputation: 17687

This answer is specific to IntelliJ products such as IDEA / WebStorm / PHPStorm when using organizations.

I had this problem with WebStorm when trying to push to a repository that was part of an organization, meanwhile pushing to a repository within my normal private account worked.

Also, pushing to my organizational repository with IntelliJ IDEA worked

So I thought this could only be something related to a setting that differs between both IDEs, and I found out that I had the checkbox "Use credential helper" enabled in WebStorm, and disabled in IDEA.

enter image description here

Disabling the credential helper made it working!!

Upvotes: 1

Coconut
Coconut

Reputation: 2222

My solution was this:

git remote rm origin
git remote add origin https://[email protected]/username/reponame.git

Similar to Emi-C's answer but without passwords.

Upvotes: 4

Amarjeet Sarma
Amarjeet Sarma

Reputation: 101

Before following this, make sure you've write permission to the repo. If you're still getting the error, do the following :

  1. Generate a personal access token from your account from Settings > Developer Settings > Personal Access tokens. Keep the token safe somewhere.

  2. Go to your repository and run the following:

    git remote rm origin

  3. Then add a new origin along with your username:

    git remote add origin https://[email protected]/REPOSITORY_LINK.git

  4. Now when you push the code, a prompt will show up asking for your password or personal access token. Paste the token that we generated in the first step in the field, and we're done.

Upvotes: 4

Kasper Gyselinck
Kasper Gyselinck

Reputation: 175

In my case this was caused by git using the wrong ssh private key. I was given access to the repository under a specific github user account I am using for school. My default ssh private key was unfortunately linked to a different github account.

If you do ssh -T [email protected] ssh will automatically use your id_rsa private key to connect to github.

Using ssh -i ~/.ssh/<some-key> -T [email protected] should result in github greeting you with the account you linked to that key.

So what happened in my case was that git was using my default ssh private key which was linked to the wrong github account which didn't have access to the private repository I was trying to access.

To solve this I told git to use the correct ssh command in the local git config for my repo using the command: git config core.sshCommand "ssh -i ~/.ssh/<correct private key here>"

Viewing the git configuration git config -l should show that the line was properly added.

Upvotes: 1

Leo Seyers
Leo Seyers

Reputation: 340

I solved that issue by re-authentifacating with Github.

If you have Github CLI, you can type gh auth login

Upvotes: 6

Rafa
Rafa

Reputation: 61

My problem was that I created a personal developer token without permissions

Upvotes: 1

Claudio
Claudio

Reputation: 134

I (and many others) have had this problem since may 2021. Something seems to have changed in actions/checkout@v2 (GitHub issue: https://github.com/actions/checkout/issues/254)

I resolved it by changing the way the runner authenticates to the repo by using this step.

- name: Bump version
    env:
      NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
    run: |
      npm run release
      git remote rm origin
      git remote add origin https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/project/repo.git
      git remote -v # for debug only 
      git show-ref # for debug only 
      git push --follow-tags origin HEAD:master

All you need to do is to change the repo url. Username and password will be replaced at runtime by the GitHub runner. This works for both actions/checkout@v1 and actions/checkout@v2 (haven't tested others).

Also many snippets you find online already come with a permission restriction that will prevent you from pushing back to the repo

permissions:
   packages: write
   contents: read

Make sure you remove this or grant your action contents:write permission if you need to push a tag or commit release notes and package bumps.

Upvotes: 1

Tomas Lukac
Tomas Lukac

Reputation: 2255

Using Ubuntu, I always have to add remote using SSH instead of HTTPS

git remote add origin [email protected]:username/project.git

instead of

git remote add origin https://github.com/username/project.git

Upvotes: -1

Viraj Singh
Viraj Singh

Reputation: 2358

enter image description here

Step 1:

Copy the link from the HTTPS

Step 2:

in the local repository do

git remote rm origin

Step 3:

replace github.com with [email protected] in the copied url

Step 4:

git remote add origin url

Upvotes: 1

SandroMarques
SandroMarques

Reputation: 6544

If you use Git on Windows, try to clear your credentials:

  1. Locate "credential manager" (should be in your Control Panel)
  2. Remove all credentials related to GitHub

enter image description here

Upvotes: 149

Rajan rek
Rajan rek

Reputation: 390

you have to generate ssh key and add it in your github account in settings go to your project where you clone inside that run these command.-

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

after the command you will get some options path and name can be leave empty and you can put password.

2-eval $(ssh-agent -s) .

3-ssh-add ~/.ssh/id_rsa

after this command you have to put same password that you created in 1st command

and after that you can check your default home directory or whatever directory it is showing on the terminal .pub file open and copy the key and past in github settings new ssh

Upvotes: -1

R0bertinski
R0bertinski

Reputation: 609

Normally it happens because the project is private and you have not rights to write it. I had the same "problem" a few times, and it was for that reason. If the project it is yours, just create a private and a public key following this link: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent and add them to the "SSH and Key" section on gitHub, then you will be able to push to the repo. In the other hand if the project it is not your, ask the owner to give you the rights for it.

Upvotes: 4

ktolbol
ktolbol

Reputation: 91

To solve this problem (on Linux), I merely had to run this:

git config --global --unset credential.helper

Upvotes: 8

Misterwyz
Misterwyz

Reputation: 101

Just use the SSH remote url instead of the HTTPS

Upvotes: 5

gs1208
gs1208

Reputation: 83

I can explain how i get into the similar situation, and then will list steps that i have taken to solve this issue.

I am using
Windows 10,
git: git version 2.27.0.windows.1.

I had already setup the git and was doing git push activities. Windows Credential Manager stores the username and password so you don't have to enter username and password every git remote activities.

The encounter this problem, when i added another github account and used --local git settings. After few days, I encounter the Repository not found problem, upon investigation i found:

  1. Even if you remove the git details from Windows Credential Manager, it will save again the username, email details you enter.

So, if you are using two git accounts, you need to use (git bash as an administrator)

git config --edit --system 

and remove the

helper = manager 

line so that it is no longer registered as a credential helper. But it will ask you login details every time you do any remote activities.

How do I disable Git Credential Manager for Windows?.

To check remote origin, user details

git config --list --show-origin

Upvotes: 5

davyCode
davyCode

Reputation: 459

I ran into the same issue on a MAC trying to pull from a private repo i was previously connected to.

I solved it by including my username in the repo url:

git remote set-url origin https://<YOUR_USER_NAME_HERE>@github.com/<YOUR_USER_NAME_HERE>/<REPO>.git

Then i was able to pull from the repo.

For a new repo you want to clone:

git clone https://<YOUR_USER_NAME_HERE>@github.com/<YOUR_USER_NAME_HERE>/<REPO>.git    

It will prompt you to enter your password to that account, you're good to go afterwards.

Upvotes: 9

Safeer
Safeer

Reputation: 1467

I was having the same issue with one of my Github Repository.

Way around:

Used SSH instead of HTTPS and then push/pull started working fine.

Upvotes: 5

Daniel
Daniel

Reputation: 2605

I had the same problem using Android Studio, I was unable to push commits because of the auth error.

My working temporary solution was to use the GitHub desktop app to push my commits and it works fine.

Upvotes: 0

Related Questions