Git:说 origin 已经存在于 "NEW"(init) 存储库中,使用 shell 但安装了 Github for Windows

标签 git github github-for-windows

我安装了适用于 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/

相关文章:

git - 解决方案具有位于解决方案文件夹之外的项目

github - 如何为 github 和 npm 指定不同的自述文件

heroku - 如何设置git远程heroku?

git - 我应该在哪里上传 github 分支的构建文件?

git - 如何使用 dvc 工作流程添加/更新数据?

github - 如何从 GitHub 安装程序?

jenkins - 无法连接到存储库 : Command "git ls-remote -h

git - 将 RubyMine 与 GitHub for Windows 集成

git - 在 Windows 版 GitHub 的 bash 中安装 Git-Flow 时出错

git pull突然停止工作,排查 "Repository not found"