Reputation:
I have a couple Git repositories that all have one or more submodule referenced and both are corporate lan / internal https URLs (and thereby only accessible from the corp lan).
From the outside / public network, ssh access to the repositories IS however possible and I can mitigate switching the main repositories' URLs back and forth via a global .gitconfig url.insteadOf redirection, but that insteadOf rule doesn't seem to apply to the submodules (which also are https urls).
Is there any other way than to adapt each repository's .git/config file ... i.e something I can set in the global .gitconfig as well?
Upvotes: 4
Views: 4275
Reputation: 822
If you're not happy with changing your global configuration, then you probably need to configure each submodule separately, since each submodule is its own repository.
Fortunately git supplies git submodule foreach
command, which
Evaluates an arbitrary shell command in each checked out submodule.
What's important is that it really happens in each checked out submodule. Meaning that before you run git submodule update
some submodules will get ignored.
So
$ git config --local url."[email protected]:".insteadOf "https://github.com/"
$ git submodule foreach --recursive \
'git config --local url."[email protected]:".insteadOf "https://github.com/"'
should do the trick for the main repository, its submodules and submodules of their submodules.
Upvotes: 2
Reputation:
I could not find a way using git configuration and went with a brute force:
# test step, replace the "url = https://github.com/" manually
# verify the desired effect
# note the comma in sed command, it's unusual and valid
sed 's,https://github.com/,[email protected]:,g' .git/modules/*/config | grep url
# -i to modify the files
sed -i 's,https://github.com/,[email protected]:,g' .git/modules/*/config
from the parent repository.
or go with @torek's --global
if affecting global config is not a problem:
git config --global url."[email protected]:".insteadOf "https://github.com/"
# or
git config --global url."https://github".insteadOf git://github
# for reverse
Upvotes: 2