简体   繁体   English

我可以将 git 子模块与某种后备 URL 链接吗? 如果 SSH 克隆失败,git 应该能够使用 https 进行克隆

[英]Can I link git submodules with some kind of fallback URL? If SSH clone fails, git should be able to clone using https

(This is something that's cropped up for me mainly when using GitHub, so I don't mind too much if any solution is GitHub-specific. But the problem isn't GitHub-specific per se, and any solution needn't necessarily be either.) (这是我主要在使用 GitHub 时突然想到的东西,所以我不介意任何解决方案是特定于 GitHub 的。但问题本身并不是特定于 GitHub 的,任何解决方案都不一定是要么。)

You can always clone a public GitHub repo using https:您始终可以使用 https 克隆公共 GitHub 存储库:

git clone https://github.com/my-user-name/SDL-mirror

If you have an SSH key that GitHub knows about, you can also clone the repo using SSH:如果您有 GitHub 知道的 SSH 密钥,您还可以使用 SSH 克隆存储库:

git clone git@github.com:my-user-name/SDL-mirror.git

(I think similar options apply when using Bitbucket.) (我认为使用 Bitbucket 时也适用类似的选项。)

You have these two options when adding a submodule, too.添加子模块时,您也有这两个选项。

When adding a submodule, you'll often add the SSH version, so you can commit directly from the submodule after testing your changes in situ.添加子模块时,您通常会添加 SSH 版本,因此您可以在原位测试更改后直接从子模块提交。

But what about people trying to clone your repo?但是那些试图克隆你的 repo 的人呢? They might not have SSH access to GitHub.他们可能没有对 GitHub 的 SSH 访问权限。 So they'll clone your repo using the HTTPS URL... and then come unstuck when Git tries to clone the submodules using the SSH URLs.因此,他们将使用 HTTPS URL 克隆您的存储库......然后当 Git 尝试使用 SSH URL 克隆子模块时会解脱。

This can also be an issue if you use a Git repo for system provisioning.如果您使用 Git 存储库进行系统配置,这也可能是一个问题。

Ideally, I'd like Git to pull from the SSH URL if possible, and the HTTPS URL if not.理想情况下,如果可能,我希望 Git 从 SSH URL 中提取,否则从 HTTPS URL 中提取。 That should make things work out of the box for everybody.这应该让每个人都能开箱即用。 Is there some way I can get it to do that?有什么办法可以让它做到这一点吗?

What you can do is:你可以做的是:

That way, for your local repo, you are always using ssh, but for anyone cloning your repo, there are only https references.这样,对于您的本地存储库,您始终使用 ssh,但对于克隆您的存储库的任何人,只有 https 引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM