Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."
Solution 1
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
Solution 2
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
Solution 3
As Matt Clark stated above
However, origin might not be set, so skip the deleting step and simply attempting to add can clear this up.
git remote add origin <"clone">
Where "clone" is simply going into your GitHub repo and copying the "HTTPS clone URL" and pasting into GitBash
Solution 4
This is the way I updated the master branch
This kind of error occurs commonly after deleting the initial code on your project
So, go ahead, first of all, verify the actual remote version, then remove the origin add the comment, and copy the repo URL into the project files.
$ git remote -v
$ git remote rm origin
$ git commit -m "your commit"
$ git remote add origin https://github.com/user/repo.git
$ git push -f origin master
Solution 5
Make sure the config file at .git is correct...Check URL & Make sure your using the correct protocol for your keys ...ProjectWorkspace/.git/config
~Wrong url for git@bitbucket
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = gitbucket.org:Prezyack/project-one-hello.git
fetch = +refs/heads/*:refs/remotes/origin/*
~Wrong URL for SSH...
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://[email protected]/emmap1/bitbucketspacestation.git
[branch "master"]
remote = origin
merge = refs/heads/master
We are looking at the URL... e.g: For bitbucket, expect [email protected] its gitbucket.org. make the necessary changes.. SAVE Try pushing again.
Related videos on Youtube
Thibaud Clement
Updated on July 08, 2022Comments
-
Thibaud Clement almost 2 years
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
mymaster
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
orgit 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?
-
Himanshu Kriplani about 4 yearsI had a similar error, But my problem was I had initialized git in the parent directory of the current folder I was trying it. Just in case if anyone is still facing, can look where the git is initialized and then try again.
-
Carol-Theodor Pelu almost 6 yearsIt worked for me without the
ssh://
in front of[email protected]:1234/myRepo.git
-
StaticVariable over 5 yearsI was reading this question if you could help with the new repository push error as well?
-
Kache almost 4 yearsTry adding explanations to your answer in a way that addresses the question and attempts to help a reader understand. Currently, it just reads like some anecdote and wouldn't even work in the general case (e.g.
https://github.com/
is the website root and a git repo) -
Uriahs Victor almost 3 yearsI renamed my remote branch from upstream to origin and it caused the error, after completely deleting the remote reference using
git remote remove origin
and then adding it again usinggit remote add origin <url>
then it worked fine