Managing multiple upstream git submodule URL's in private repo

Viewed 426

I am developing applications for my company where we use a private git repo inside our company's network. I am able to work with our git projects both internally and externally through the use of multiple upstreams to the same host (but through different SSH ports), like so:

external      ssh://user@externalhost.example.com:1234/var/git/project.git
origin        ssh://user@internalhost.example.com/var/git/project.git

My submodules work only when I connect internally. Here's an example submodule upstream:

[submodule "common-code"]
    path = common-code
    url = ssh://user@internalhost.example.com:/var/git/common-code.git

Is there a way to manage multiple upstreams for submodules so that I can work with them both internally and external to my company network?

Note: I've found some old posts about this on SO but they didn't really resolve the OP's answer or were vague about how to do so.

1 Answers

The URL for a submodule can be a relative URL. This is only potentially helpful, as it is then relative to the default remote URL. So for a single clone, it still points to a single URL (either the internal or the external, depending on which remote URL is the default); but you can create clones for internal use and separate clones for external use, and then using a relative URL for the submodule ought to work.

If for whatever reason you really need to use a single clone - perhaps you're working on a laptop and switch back and forth frequently enough that it would be inconvenient to share local changes between two clones - then the only option I can think of would be to create a script to modify the local configuration when you switch between internal and external. Still I would think it best not to be tweaking the submodule paths, so I'd use a relative URL for that, and just modify the remote configuration as you move from internal to external or vice versa.

Related