Search code examples
gitsshgit-submodules

git - Can you clone via HTTPS even if SSH-style git@github is used


I'm trying to clone a git repository which has submodules via git submodule update --init --recursive. These submodules all use "[email protected]:foo/bar.git" URLs. Unfortunately, my work place is preventing SSH URLs from their firewall. I can, however, clone via HTTPS, with no problems.

As mentioned, the submodule URLs are hard-coded in the repository to use SSH. Is there a way to tell git to clone these submodule repositories using HTTPS without instead of SSH making any direct modifications to the git repository?


Solution

  • Use git config --global url.<base>.insteadOf to substitute URLs on the fly. Something like

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

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

    See more examples in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof