简体   繁体   English

如何对 git 子模块使用相同的协议?

[英]How to use same protocol for git submodules?

In a git repository RI have a submodule that I initialized with the following command:在 git 存储库 RI 中有一个我使用以下命令初始化的子模块:

git submodule add git@mygitserver...

Now a user just cloned R using https and get an error when running现在用户刚刚使用https克隆了 R 并在运行时出错

git submodule init
git submodule update

because he doesn't have ssh (with public key uploaded on the server) access.因为他没有 ssh(在服务器上上传了公钥)访问权限。 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 ?所以我的问题是,是否可以创建一个子模块,该子模块将自动使用与用于在git submodule update命令上克隆父存储库的协议相同的协议?

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.这样,https url 将始终用于 mygitserver(主 repo 或子模块),而不是 ssh 的。

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文件使用相对 url,并且如果 repo 总是通过“完整 url”克隆,那么事情应该可以正常工作:

.gitmodules : .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.但是,如果用户选择clone git@github.com:user/repo.git (注意: ),则update将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM