从本地存储库中删除上游 Git

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

$ git remote -v

to get a view of my local repository. I messed up when trying to go upstream:

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

当我应该把 Foo 大写的时候:

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

The question is how do I remove the upstream because every time I try and change this it comes back with creating a fatal error?

174578 次浏览

git remote manpage is pretty straightforward:

使用

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

或者直接更新网址:

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

or if you are comfortable with it, just update the .git/config directly - you can probably figure out what you need to change (left as exercise for the reader).

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

===

* 关于‘ git remote rm’vs‘ git remote move’-这个改变围绕 git 1.710.3/1.7.122-参见

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.

使用 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并查看远程的名称。(如果在窗口而不使用 Powershell,则可以使用 type .git/config。)

输出将显示为您的 git 回购配置的远程,例如,

[remote "origin"]

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

$ git remote rm origin

如果你没有“上游”遥控器,你就不能移除它。

$ git remote remove <name>

也就是说。

$ git remote remove upstream

应该可以了

In git version 2.14.3,

您可以使用

git branch --unset-upstream

The above command will also remove the tracking stream branch, hence if you want to rebase from repository you have use

git rebase origin master

而不是 git pull --rebase