How to use same protocol for git submodules?
Asked Answered
F

2

8

In a git repository R I have a submodule that I initialized with the following command:

git submodule add git@mygitserver...

Now a user just cloned R using https and get an error when running

git submodule init
git submodule update

because he doesn't have ssh (with public key uploaded on the server) access. So my question is, is it possible to create a submodule that will automatically uses the same protocol than the one used to clone the parent repository on the git submodule update command ?

Fourgon answered 12/4, 2016 at 5:57 Comment(0)
V
8

That user can set the config:

git config --global url.https://mygitserver/.insteadOf ssh://git@mygitserver/
# or possibly (to be tested)
git config --global url.https://mygitserver/.insteadOf git@mygitserver/

That way, https urls will always be used for mygitserver (main repo or submodules), instead of ssh ones.

Vaunt answered 12/4, 2016 at 6:4 Comment(0)
T
2

I haven't tested in detail (only some cases), but it seems that if your .gitmodules file uses relative urls and if the repo is always cloned via a "full url", then things should work:

.gitmodules:

 [submodule "same_users"]
    path = same_users
    url = ../something.git
 [submodule "other_user"]
    path = same_users
    url = ../../different-user/something.git

 # Maybe even this?
 [submodule "other_server"]
    path = same_users
    url = //[email protected]/joe_r_user/hacks.git

Clone:

git clone ssh://[email protected]/user/repo.git ./ssh
cd ssh
git submodule update --init --recursive

However if the user chooses clone [email protected]:user/repo.git (note the :), the update won't work.

Timofei answered 17/3, 2020 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.