我既不能添加也不能删除具有特定名称的 git 遥控器,它不会出现在 `.git/config` 中

I can neither add nor remove a git remote with a specific name, it does not appear in `.git/config`

我在尝试将上游远程添加到我的 git 存储库时不小心颠倒了一些参数的顺序。

即我输入

git remote add https://github.com/jupyter/nbconvert.git upstream

这导致了

fatal: 'https://github.com/jupyter/nbconvert.git' is not a valid remote name

但是现在,

git remote add upstream https://github.com/jupyter/nbconvert.git

returns:

fatal: remote upstream already exists.

git remote rm upstream

returns:

error: Could not remove config section 'remote.upstream'

然后,

git remote -v

我明白了

origin  git@github.com:michaelpacer/nbconvert.git (fetch)
origin  git@github.com:michaelpacer/nbconvert.git (push)
upstream

当我查看我的 .git/config 时,没有 [remote "upstream"] 的实例……

所以我有点难过。

你必须这样做:

git remote add origin <url>

添加额外的远程存储库*

git remote add <name1> <url1>
git remote add <name2> <url2>

设置上游*

git remote add upstream <url>

我不确定这是怎么发生的,但我相信问题是你的 --global 配置中有一个非空的 [remote "upstream"] 部分(通常是 $HOME/.gitconfiggit config --global --edit 将在您的编辑器中调出正确的文件)。我验证了一旦处于这种状态,git remote rm upstream 就会按照您所看到的方式运行。

如果你清除它,添加名为 upstream 的远程的正常方法应该再次开始工作。您可以使用您的编辑器将其清除,或使用:

git config --global --remove-section remote.upstream