我安装了适用于 Windows 的 Git,尽管我使用的是 shell 而不是 Windows 界面。
如果我执行 git init
,然后尝试执行
git remote add origin git@github.com:someuser/testme.git
出现以下错误
fatal: remote origin already exists.
所以我做了一个
git remote -v
它返回以下内容
origin
upstream
所以它出现在那里但没有设置 URL,我不明白为什么它在那里?
如果我做一个
git remote rm origin
它产生这个
error: Could not remove config section 'remote.origin'
它说它不能删除 remote.origin 配置部分;我检查了我的主目录下的 .gitconfig,但我没有看到任何东西。
无论如何,我可以通过使用来解决这个问题
git remote set-url origin git@github.com:someuser/testme.git
但我感到很困惑,因为我以前使用过 Git,但从未发生过这种情况。
这可能与 Git for Windows 有关吗?
最佳答案
我是把它放进去的开发者。这就是我将它添加到系统 gitconfig 的原因,它非常有用!
## Because of this change, git fetch knows about PRs
git fetch
## Now, I can merge PRs by number
git merge origin/pr/24
## See changes from PR #53
git diff master...origin/pr/53
## Get the commit log from PR #25
git log origin/pr/25
不幸的是,这确实会导致 origin 远程始终存在,即使它不存在也是如此。
解决方法
每当你看到 git remote add origin https://...
时,改为:
git remote set-url origin https://...
关于Git:说 origin 已经存在于 "NEW"(init) 存储库中,使用 shell 但安装了 Github for Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17012211/