简体   繁体   English

Git - 致命:远程来源已经存在

[英]Git - fatal: remote origin already exists

I can not create origin remotely with remote command:我无法使用remote命令远程创建原点:

$ 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.解决方案:我使用的是 Github 或 Git Shell 附带的 Powershell,因为它也被称为做我的教程,一旦我切换到 Git Bash,它就可以正常工作。

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 git 远程 rm 起源

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).为了使用 git push,你必须在 local_branch 后面指定最终目的地(在我自己的例子中,它是本地分支的 master 和远程分支的 main)。 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.您的来源没有与之关联的 url。 It's actually name value pair.它实际上是名称值对。 So when you say "git push origin master", Git substitues the value of origin.所以当你说“git push origin master”时,Git 会替换 origin 的值。 In my case, it would be "/mnt/temp.git".就我而言,它将是“/mnt/temp.git”。

Now what can you do ?现在你能做什么?

Try this:尝试这个:

1) Clone the repository in another directory. 1)将存储库克隆到另一个目录中。

2) run " git remote -v " and get the value of origin 2) 运行“ git remote -v ”并获取origin的值

3) In your case it looks like the value is " https://github.com/LongKnight/git-basics.git " 3)在您的情况下,该值看起来是“ 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 " 4)所以回到你的工作目录,然后运行“ git remote add origin2 https://github.com/LongKnight/git-basics.git

5) Run " git remote remove origin " 5) 运行“ git remote remove origin

6) Now run " git remote rename origin2 origin " 6) 现在运行“ git remote rename origin2 origin

7) Check what's the value of origin now with "git remote -v" 7) 现在用“git remote -v”检查 origin 的值是多少

8) It should be correctly set now. 8) 现在应该正确设置。 If so, run " git push "如果是这样,运行“ git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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