简体   繁体   中英

Git - fatal: remote origin already exists

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.

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.

try this

git remote rm origin

then,

git remote add origin https://yourLink

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

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 "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM