Home > Enterprise >  How to 'git clone --recurse-submodules' a github repo using ssh key, without being asked f
How to 'git clone --recurse-submodules' a github repo using ssh key, without being asked f

Time:11-08

Hello StackOverflow Community Members,

I'm looking for some help 'git clone --recurse-submodules'ing a github repo using an ssh key, without being asked for username and password.

I have no issues cloning repos using a properly setup ssh key:

git clone [email protected]:{company_name}/{main_repo}.git

Everything works as expected here and project files are retrieved without asking me for a username and password.

This is not the case however when I try to automatically initialize and update each submodule in the repository (per instructions):

git clone --recurse-submodules [email protected]:{company_name}/{main_repo}.git

When I run this I am asked for a username and password before any of the submodules are retrieved. This is highly undesired.

Any ideas on why I'm being asked for a username and password when I run with --recurse-submodules? I have permission to successfully clone the submodule repos individually (without inputing username and password):

git clone [email protected]:{company_name}/{submodule_repo}.git

Your brilliant assistance is greatly appreciated!

CodePudding user response:

Hard to say without looking at exact messages Git asked. Most probably it's because some submodules are written in .gitmodules with https:// protocol instead of ssh:// or git@.

In that case use git config --global url.<base>.insteadOf to substitute URLs on the fly. Something like

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

(Please note the colon after [email protected]:; it's necessary to map https://github.com/user/repo.git to [email protected]:user/repo.git).

See more examples in https://stackoverflow.com/search?q=[git-submodules] insteadof

CodePudding user response:

Turns out some admin mods on the submodule permissions were causing the issue (i.e. my permission to access one of the submodule repos was temporarily removed).

  • Related