问题
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 ?
回答1:
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.
回答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 = //git@gitlab.com/joe_r_user/hacks.git
Clone:
git clone ssh://git@github.com/user/repo.git ./ssh
cd ssh
git submodule update --init --recursive
However if the user chooses clone git@github.com:user/repo.git (note the :), the update won't work.
来源:https://stackoverflow.com/questions/36564696/how-to-use-same-protocol-for-git-submodules