How to use same protocol for git submodules?

白昼怎懂夜的黑 提交于 2020-03-20 06:35:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!