Git - fatal: remote origin already exists
Asked Answered
C

4

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.

Carlow answered 21/8, 2014 at 7:19 Comment(6)
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.Flowerage
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,Carlow
@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...Culdesac
Yeah it's all part of learning how things are done on the site, Thanks for the replyCarlow
I stucked for more than 8 hours until I tried Git Bash.(Dianemarie
Possible duplicate of Github "fatal: remote origin already exists"Floorage
A
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.

Arsis answered 21/8, 2014 at 12:35 Comment(1)
Yeah, This looks betterPhooey
G
1

try this

git remote rm origin

then,

git remote add origin https://yourLink

Greenhaw answered 1/1, 2020 at 7:15 Comment(1)
Why? This is what git remote set-url is for.Arsis
E
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
Eberly answered 16/2, 2021 at 12:53 Comment(0)
P
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"

Phooey answered 21/8, 2014 at 10:48 Comment(5)
Thanks for your reply Mayur, i tried it and still had the same problemCarlow
what does git remote -v say ?Phooey
It still said origin, i tried to use git bash instead of github's powershell and it worked first time, the fetch and push look just as you said they should, should i avoid github client?Carlow
Are you on windows ? What are you using for git operations ?Phooey
windows 7, i downloaded git and github , and installed them both, i really didn't know what i was doing at the timeCarlow

© 2022 - 2024 — McMap. All rights reserved.