Tom Seddon Tom Seddon - 28 days ago 8
Git Question

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.)

You can always clone a public github repo using https.

git clone

If you have an SSH key that github knows about, you can also clone it using SSH.

git clone

(I think similar options apply when using 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.

But what about people trying to clone your repo? They might not have SSH access to github. 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.

This can also be an issue if you use a git repo for system provisioning.

Ideally, I'd like git to pull from the SSH URL if possible, and the https URL if not. 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.