【问题标题】:Git Submodule update over https通过 https 更新 Git 子模块
【发布时间】:2024-04-13 17:45:02
【问题描述】:

我坐在只允许 http/https 流量的代理上,我可以从 Github 克隆存储库,但我必须使用 https URL 和用户名/密码来获取/推送。

现在我的问题是一个带有子模块的存储库,当我执行git submodule update 时它会超时,我只能假设这是因为它使用的是被阻止的 SSH 连接。 (它甚至不要求我在私人仓库上输入密码)

【问题讨论】:

  • 这个问题也解决了Permission denied (publickey)错误的问题。

标签: git proxy git-submodules


【解决方案1】:

在你的 repo 根目录下的 .gitmodules 文件中,以及在 .git/config 文件中,你应该找到你的子模块的部分。您可以在那里编辑 url,以便通过 https 请求而不是 ssh 访问它。

当然它可能已经是一个 ssh url,在这种情况下问题可能是其他问题,但这是首先要检查的地方。

【讨论】:

  • 这很有帮助,但我的问题稍微复杂一点,因为我在 subrepos 中有 subrepos。这是我在 Linux 中编辑所有正确文件的方法: sed -i -e 's/git:\/\//http:\/\//g' .gitmodules;找 。 -name config -type f -exec sed -i -e 's/git:\/\//http:\/\//g' {} \;
  • 在编辑 .gitmodules 后运行 git submodule sync,正如 François Koessler 的回答所暗示的那样,这是实现此功能的必要步骤!
  • 我没有阅读您的评论。我不得不手动更改.git/config 文件
【解决方案2】:

使用 https url 编辑您的 .gitmodules 文件,例如:

[submodule "vendor/engines/fat_free_crm"]
    path = vendor/engines/fat_free_crm
    url = https://github.com/fatfreecrm/fat_free_crm.git

然后运行git submodule sync 将更改反映到您的.git/config 文件中。

致谢:https://*.com/a/6632693/1273077

【讨论】:

    【解决方案3】:

    如果您不想自己手动更改 .gitmodules 文件,您现在可以使用 git CLI 来完成(确保您的 git 版本不太旧)。

    这将为您进行更改:

    git submodule  set-url [--] <path> <newurl>
    

    例子:

    git submodule set-url somedir https://github.com/somename/somerepo.git
    

    【讨论】: