+3 votes
1 view
in Devops and Agile by (21.4k points)
edited by

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 the next steps of the app development,

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 anymore 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?

3 Answers

+5 votes
by (36.1k points)

This error occurs due to the remote is not added so what you could do is:

git remote -v

git remote remove <present remote name>

Then add 

git remote add <remote-name(ie:- origin)> <githuburl>

Then you could do: 

git push origin master

 So that this will work. Hope this will help you.

by (21.4k points)
Thank you this works for me.
by (15.9k points)
This worked for me as well!
by (32.4k points)
This answer was helpful.
Thanks!
by (36.4k points)
A similar error appears while pulling the changes from the origin. If you are trying in Intellij from the menu options, the pull might not work directly. Go to terminal and type this command and this should work out:
git pull origin master
by (6.1k points)
Worked for me.
+1 vote
by (41.4k points)

As @yeshwanth.intelli stated above

However, the 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 just going into your GitHub repo and copying the "HTTPS clone URL" and pasting into GitBash

by (25.4k points)
Nice observation !
by (39.2k points)
This sounds doable, good answer
0 votes
by (46.1k points)

The error occurs because sometimes you don't have a local REF for pushing that branch back to the origin. So in those cases, you can try:-

git push origin master:master

This explicitly indicates which branch to push to and from where.

...