GIT Push: ERROR Repository Not Found

GIT Push: ERROR Repository Not Found

·

2 min read

(this follows on from my previous article about Using Multiple GitHub Accounts)

Running into the following error when trying to push or pull a new repository for the first time with GIT. Here is what caused the issue for me.

C:\code\git\tutorials\isnotnulldev-cucumber-starter>git push --set-upstream origin main
Enter passphrase for key '/c/Users/Michael/.ssh/isnotnulldev/id_ed25519': 
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

In my case, I thought it was something to do with the multi-account configuration but it turns out, it was way simpler than that. I had used .repo instead of .git for some silly reason.

Two ways to fix this, the short and long are below when using the SSH agent:

Short:

1) Get the URL from GitHub for your repo

2) Run the following command:

# Single account
git remote add origin git@github.com:<github-username>/<repository>.git

# Multiple GitHub accounts using the alias in the .ssh/config file
git remote add origin git@<alias-in-ssh-config>:<github-username>/<repository>.git

Or long:

1) Go to the directory in which your project resides on the local laptop

2) In that directory, there will be a .git folder. Change into that directory.

3) Open up the config file. Take a look at the URL.

4) Copy the SSH URL from GitHub for your repo to the url field in the config file ( replacing github.com with your alias specified in .ssh/<username>/config if you are using multiple accounts) and save

Now, run the command again, it should pull/push correctly (or not in my case, but it succeeded):

This assumes that:

  • You've created an empty repo on GitHub already

  • You've set up your SSH private/public key pair.

Troubleshooting:

  • Check what your remote is set as:

      git remote -v
    
  • Check what GIT is doing:

      # Windows
      SET GIT_TRACE=1  
    
      # Bash
      export GIT_TRACE=1
    
      # Turn it off by setting it to 0
    
  • If when pushing for the first time, you get the following error fatal: refusing to merge unrelated histories, use the flag --allow-unrelated-histories in the push command.