111

我正在使用 ruby​​ on rails 应用程序,我正在尝试同步一个 fork。值得一提的是,我也在 Mac 上。我采取了以下行动:

$ git remote -v

查看我的本地存储库。我想去的时候搞砸了upstream

$ git remote add upstream https://github.com/foo/repo.git

当我应该大写 Foo 时:

$ git remote add upstream https://github.com/Foo/repos.git

问题是如何删除,upstream因为每次我尝试更改它都会返回创建fatal错误?

4

4 回答 4

176

使用 git 版本 1.7.9.5 没有远程的“删除”命令。请改用“rm”。

$ git remote rm upstream
$ git remote add upstream https://github.com/Foo/repos.git

或者,如上一个答案中所述, set-url 有效。

我不知道命令何时更改,但 Ubuntu 12.04 附带 1.7.9.5。

编辑:有些人似乎遇到了他们没有“上游”遥控器的情况。执行cat .git/config并查看遥控器的名称。(如果在 Windows 上而不使用 powershell,您可以使用type .git/config。)

输出将显示为您的 git 存储库配置的遥控器,例如,

[remote "origin"]

将您要删除的遥控器的名称替换为:

$ git remote rm origin

如果您没有“上游”遥控器,则无法将其移除。

于 2014-02-17T17:02:47.427 回答
42

git remote 手册页非常简单:

利用

Older (backwards-compatible) syntax:
$ git remote rm upstream
Newer syntax for newer git versions: (* see below)
$ git remote remove upstream

Then do:    
$ git remote add upstream https://github.com/Foo/repos.git

或者直接更新 URL:

$ git remote set-url upstream https://github.com/Foo/repos.git

或者,如果您对它感到满意,只需直接更新 .git/config - 您可能会弄清楚您需要更改什么(留给读者作为练习)。

...
[remote "upstream"]
    fetch = +refs/heads/*:refs/remotes/upstream/*
    url = https://github.com/foo/repos.git
...

===

* 关于 'git remote rm' 与 'git remote remove' - 这在 git 1.7.10.3 / 1.7.12 2前后发生了变化- 请参阅

https://code.google.com/p/git-core/source/detail?spec=svne17dba8fe15028425acd6a4ebebf1b8e9377d3c6&r=e17dba8fe15028425acd6a4ebebf1b8e9377d3c6

Log message

remote: prefer subcommand name 'remove' to 'rm'

All remote subcommands are spelled out words except 'rm'. 'rm', being a
popular UNIX command name, may mislead users that there are also 'ls' or
'mv'. Use 'remove' to fit with the rest of subcommands.

'rm' is still supported and used in the test suite. It's just not
widely advertised.
于 2013-11-06T00:02:33.763 回答
29
$ git remote remove <name>

IE。

$ git remote remove upstream

这应该够了吧

于 2018-05-22T02:15:08.957 回答
17

在 git 版本 2.14.3 中,

您可以使用删除上游

git branch --unset-upstream

上面的命令还将删除跟踪流分支,因此如果你想从你使用的存储库中变基

git rebase origin master 

代替git pull --rebase

于 2019-04-29T13:26:16.633 回答