将 ssh 与 https 与 github 子模块一起使用

Using ssh vs https with github submodules

我想建立一个带有子模块的 public GitHub 仓库。 GitHub 提供两种连接方式 - https:...git@... 协议。对于项目团队来说,git@... 更容易使用,因为我们都使用适当的 ssh 证书。但是对于不是团队成员的临时用户,https:... 是唯一的选择。 git 子模块需要完整的 URL。

我们如何设置存储库子模块,以便开发人员和临时贡献者都能同样好地使用该系统?谢谢!

首先,它不是 "git protocol",实际上是 SSH one,URL 就像 git@github.com:user:repo
(其实还有一个git protocol,现在已经不用了)

其次,将 URLs 保留为子模块的 https:使用凭据管理器(如 GCM for Windows)很容易缓存凭据(username/password)。
但这意味着那些 users need to be added as contributors(无论您是否使用 HTTPS 或 SSH URLs)

使用 https:// 协议发布您的子模块,但让所有开发人员使用 ssh:// 协议。 Git 可以 substitute one protocol with the other on the fly:

git config url."ssh://git@".insteadOf https://

之上构建,我发现我必须指定 --global 以确保配置也适用于子模块。这是命令我运行:

git config --global 'url.ssh://git@example.com.insteadOf' 'https://example.com:PORT'

(作为答案发布,因为我没有评论的声誉)