Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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:

git clone [email protected]:my-user-name/SDL-mirror.git

(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?

like image 503
Tom Seddon Avatar asked Nov 05 '16 00:11

Tom Seddon


1 Answers

What you can do is:

  • register your submodules with an https url (or change its current ssh url to an https one)
  • locally instruct Git to use ssh instead:

    git config --global url.ssh://[email protected]/.insteadOf https://github.com/
    

That way, for your local repo, you are always using ssh, but for anyone cloning your repo, there are only https references.

like image 138
VonC Avatar answered Oct 22 '22 11:10

VonC