26

I can not create origin remotely with remote command:

$ git remote add origin https://github.com/LongKnight/git-basics.git
fatal: remote origin already exists.

To solve the error, I have tried this:

$ git remote -v origin
$ git remote -v show origin

It is not uploading the files from my local repository to the remote:

$ git push -u origin master
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.

Does each repository have its own origin?


Solution: I was using the Powershell that came with Github or Git Shell as it is also called to do my tutorial, once I switched to Git Bash it worked fine.

Kara
  • 6,115
  • 16
  • 50
  • 57
Brad Thrumble
  • 291
  • 1
  • 3
  • 7
  • 2
    Your question is very unstructured and it's not clear what exactly you are asking. If you have multiple questions then ask multiple questions. At the moment I'm not sure what you want to know. – Sascha Wolf Aug 21 '14 at 07:51
  • My apologises, i tried to put in as much information as i could for people to work with, does each repos have its own origin, – Brad Thrumble Aug 21 '14 at 08:39
  • @BradThrumble Don't take it bad. It takes a while to get used to the format of the site. Just endeavour to be as to-the-point as possible. There is still time to improve your question before it gets downvoted into oblivion... – jub0bs Aug 21 '14 at 08:51
  • Yeah it's all part of learning how things are done on the site, Thanks for the reply – Brad Thrumble Aug 21 '14 at 13:52
  • I stucked for more than 8 hours until I tried Git Bash.( – Mike Oct 28 '14 at 09:05
  • Possible duplicate of [Github "fatal: remote origin already exists"](https://stackoverflow.com/questions/10904339/github-fatal-remote-origin-already-exists) – ranieribt Aug 10 '17 at 21:57

4 Answers4

79

A bit easier:

git remote set-url origin https://github.com/LongKnight/git-basics.git

That will replace the current origin with a new one.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

try this

git remote rm origin

then,

git remote add origin https://yourLink

1

I had a similar issue but I got it resolved using:

git remote set-url origin https://GitHub.com/Fasunle/my_portfolio.git

And then,

git push main master 

And it worked.

In order to use git push, you must specify final destination follorwed by local_branch ( in my own case, it is master for the local branch and main for the remote branch). They could however be the same. As in:

git push -u main local_branch_to_push

Or

git push -u master local_branch_to_push
Ryan M
  • 18,333
  • 31
  • 67
  • 74
0

Hmm.

It's quite strange as to why your origin doesn't have a value. Typically, it should look like this:

[mayur.n@harry_potter]$ git remote -v
origin  /mnt/temp.git (fetch)
origin  /mnt/temp.git (push)

Your origin doesn't have the url associate with it. It's actually name value pair. So when you say "git push origin master", Git substitues the value of origin. In my case, it would be "/mnt/temp.git".

Now what can you do ?

Try this:

1) Clone the repository in another directory.

2) run "git remote -v" and get the value of origin

3) In your case it looks like the value is "https://github.com/LongKnight/git-basics.git"

4) So come back to your working directory, and run "git remote add origin2 https://github.com/LongKnight/git-basics.git"

5) Run "git remote remove origin"

6) Now run "git remote rename origin2 origin"

7) Check what's the value of origin now with "git remote -v"

8) It should be correctly set now. If so, run "git push"

Mayur Nagekar
  • 813
  • 5
  • 13