Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."

I know similar questions have already been asked.

But, I believe my issue is due to a mistake I have previously made and therefore is different: let me explain.

Everything was working smoothly, as I could:

  • git add . all the files from my local repository.
  • git commit -m "message here" to add messages to my commits.
  • git push origin master to upload my files to GitHub.
  • git push heroku master to upload my files to Heroku.

However, at some point, I created a new branch locally called add-calendar-model in case next steps of the app development would go south...

... which is exactly what happened.

However, despite many attempts, I did not manage to get the initial code — i.e. the code from before I created the new branch — from the master branch to my local repository.

So, I decided to manually delete all the files from my local repository and git clone my master branch from GitHub.

This way, I got all my files back, but now, I cannot push any more to the remote repository.

Any time I try to run git push origin add-calendar-model or git push origin master, I get the following error:

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

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

I am not very comfortable with Git and GitHub, as you may have guessed by now, and I have to admit that I have no clue about how to fix this.

Any idea?

like image 486
Thibaud Clement Avatar asked Oct 09 '22 02:10

Thibaud Clement


People also ask

Does not appear to be a git repository fatal could not read from remote repository?

Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.

How do you fix fatal could not read from remote repository please make sure you have the correct access rights and the repository exists?

The Git “fatal: Could not read from remote repository” error occurs when there is an issue authenticating with a Git repository. This is common if you have incorrectly set up SSH authentication. To solve this error, make sure your SSH key is in your keychain and you connecting to a repository using the correct URL.


2 Answers

First, check that your origin is set by running

git remote -v

This should show you all of the push / fetch remotes for the project.

If this returns with no output, skip to last code block.

Verify remote name / address

If this returns showing that you have remotes set, check that the name of the remote matches the remote you are using in your commands.

$git remote -v
myOrigin ssh://[email protected]:1234/myRepo.git (fetch)
myOrigin ssh://[email protected]:1234/myRepo.git (push)

# this will fail because `origin` is not set
$git push origin main

# you need to use
$git push myOrigin main

If you want to rename the remote or change the remote's URL, you'll want to first remove the old remote, and then add the correct one.

Remove the old remote

$git remote remove myOrigin

Add missing remote

You can then add in the proper remote using

$git remote add origin ssh://[email protected]:1234/myRepo.git

# this will now work as expected
$git push origin main
like image 100
Matt Clark Avatar answered Oct 12 '22 12:10

Matt Clark


It works for me.

git remote add origin https://github.com/repo.git
git push origin master

add the repository URL to the origin in the local working directory

like image 29
vinod Avatar answered Oct 12 '22 11:10

vinod