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

use*_*138 70 git repository git-fetch

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

$ git remote -v
Run Code Online (Sandbox Code Playgroud)

获取我的本地存储库的视图.我试图去的时候搞砸了upstream:

$ git remote add upstream https://github.com/foo/repo.git
Run Code Online (Sandbox Code Playgroud)

什么时候我应该大写Foo:

$ git remote add upstream https://github.com/Foo/repos.git
Run Code Online (Sandbox Code Playgroud)

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

bma*_*ton 129

使用git版本1.7.9.5,远程没有"删除"命令.请改用"rm".

$ git remote rm upstream
$ git remote add upstream https://github.com/Foo/repos.git
Run Code Online (Sandbox Code Playgroud)

或者,如前面的答案中所述,set-url有效.

我不知道命令何时更改,但Ubuntu 12.04随1.7.9.5一起发货.


Ber*_*t F 33

git远程联机帮助页非常简单:

使用

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
Run Code Online (Sandbox Code Playgroud)

或者直接更新URL:

$ git remote set-url upstream https://github.com/Foo/repos.git
Run Code Online (Sandbox Code Playgroud)

或者如果你对它感到满意,只需直接更新.git/config - 你可以找出你需要改变的东西(留给读者练习).

...
[remote "upstream"]
    fetch = +refs/heads/*:refs/remotes/upstream/*
    url = https://github.com/foo/repos.git
...
Run Code Online (Sandbox Code Playgroud)

===

*关于'git remote rm'vs'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.
Run Code Online (Sandbox Code Playgroud)

  • 这个答案似乎需要更新。在 git 1.7.9 中,`git remote remove upper` 会产生“错误:未知子命令:删除” (2认同)

小智 14

在 git 版本 2.14.3 中,

您可以使用删除上游

git branch --unset-upstream
Run Code Online (Sandbox Code Playgroud)

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

git rebase origin master 
Run Code Online (Sandbox Code Playgroud)

代替 git pull --rebase

  • 这对于我有两个不同上游的分支来说非常有效 (2认同)

小智 7

$ git remote remove <name>
Run Code Online (Sandbox Code Playgroud)

即。

$ git remote remove upstream
Run Code Online (Sandbox Code Playgroud)

这应该够了吧