【问题标题】:Unable to set the Git https url – it switches automatically to git protocol无法设置 Git https url - 它会自动切换到 git 协议
【发布时间】:2022-01-23 23:31:35
【问题描述】:

我今天在 Windows 机器上看到了一个非常奇怪的问题,特别是:git push origin master 会失败并显示类似以下的消息:

Unable to push to git://github.com/user/repo
Please use https://github.com/user/repo

酷,所以我们尝试了git remote set-url origin 'https://github.com/user/repo'

当我们再次尝试推送时,出现了新的错误:

Unrecognized protocol 'https

奇怪的是,这个特定的错误是由于命令提示符如何看待换行引号的方式而发生的,因此它可能与 git 无关。

再次运行,同样的命令,但没有引号:git remote set-url origin https://github.com/user/repo

现在,惊喜!当运行git remote -v 时,它应该是git://github.com/user/repo

使用 GitHub for Desktop 时会发生确切的行为。以这种格式设置 https url 时:https://github.com/user/repo 它会自动更改为git://github.com/user/repo


我们通过切换到 ssh 网址解决了这个问题,但这仍然是一个谜。


为什么会发生这种情况?如何调试?

【问题讨论】:

  • git config url.git://github.com.insteadOf ?

标签: git git-remote


【解决方案1】:

Git 有一项功能,您可以通过将一组模式转换为另一组模式来重写 URL。这是url.*.insteadOf 模式。

您可以运行git config -l --show-origin | grep insteadof 以查看您的配置中是否有任何此类条目以及它们所在的文件。如果有,您可以将它们从配置文件中删除,这应该可以使事情按预期工作。

【讨论】:

  • 确实,其中甚至有两个(git://... --> https://...https://... --> git://)。因此,它在抱怨他们两个。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 2016-06-29
  • 2019-05-28
  • 1970-01-01
  • 2018-07-26
  • 1970-01-01
  • 2017-01-06
相关资源
最近更新 更多