本文介绍了通过ssh或https自动访问git子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有一种方法可以通过相同的方法(ssh或https)自动检出git子模块作为主存储库?



背景:

我们有一个非公开的gitlab存储库( main ),它具有一个子模块( utils ),该子模块也作为非公有gitlab存储库驻留在同一台服务器上。这些存储库可以通过ssh或https访问: b
$ b



这两种变体显然都需要不同形式的身份验证,并且取决于客户端计算机和用户,其中一种或另一种是首选。

对于顶级仓库( main )来说这不是问题,因为任何人都可以选择他或她更喜欢,但是对于子模块,这取决于 .gitmodules 文件,因此(对于所有人来说)(最初)是相同的。

现在,而不是所有人必须使.gitmodules文件适应他们喜欢的任何内容,并确保它们不会意外地提交这些更改,如果有办法指定服务器和repo路径,并且git选择的方法与用于主repo,或者可以在gitconfig中设置的东西。

解决方案

我终于通过指定子模块url作为:



所以可以说通过 https://你可以通过



.gitmodules 文件如下所示:

  [submoduleutils] 
path = libs / utils
url = https://gitlabserver.com/my/path/utils.git

这意味着即使通过ssh检出主应用程序,子模块使用情况仍会通过https访问。



然而,你可以用这样的相对值替换绝对路径:

  [submodule utils] 
path = libs / utils
url = ../utils.git

并从现在起使用




  • 要么 git clone --recursive https://gitlabserver.com/ my / path / main.git

  • git clone --recursive [email protected]:my / path / main.git



可以通过任何方式获取整个存储库结构 你要。很明显,这对于相对ssh和https路径不相同的情况不起作用,但至少对于gitlab托管的存储库来说是这种情况。



这是如果您(无论出于何种原因)在两个不同的远程站点上镜像您的存储库结构,也非常方便。


Question:
Is there a way to automatically checkout git submodules via the same method (ssh or https) as the main repository?

Background:

We have a non-public gitlab repository (main) that has a submodule (utils) which is also hosted as a non-public gitlab repository on the same server. Those repositories can be accessed either via ssh or https:

Both variants obviously require different forms of authentication and depending on the client computer and the user, one or the other is preferred.

For the top level repository (main) that is not an issue, as anyone can choose the method he or she prefers, but for the sub module this depends on the .gitmodules file and hence is (initially) the same for all.
Now instead of everyone having to adapt the .gitmodules file to whatever they prefer and make sure they don't accidentally commit those changes, it would be nice, if there was a way to just specify the server and repo path and git chooses either the same method that is used for the main repo, or something that can be set in gitconfig.

解决方案

I finally solved this problem by specifying the submodules url as a relative path:

So lets say your main git repository can be reached

  • either via https://gitlabserver.com/my/path/main.git
  • or via [email protected]:my/path/main.git

And the .gitmodules file looks like this:

[submodule "utils"]
    path = libs/utils
    url = https://gitlabserver.com/my/path/utils.git

That would mean that even when you check out the main application via ssh, the submodule utils would still be accessed via https.

However, you can replace the absolute path with a relative one like this:

[submodule "utils"]
    path = libs/utils
    url = ../utils.git

and from now on use

  • either git clone --recursive https://gitlabserver.com/my/path/main.git
  • or git clone --recursive [email protected]:my/path/main.git

to get the whole repository structure which ever way you want. Obviously that doesn't work for cases where the relative ssh and the https paths are not the same, but at least for gitlab hosted repositories this is the case.

This is also handy if you (for whatever reason) mirror your repository structure at two different remote sites.

这篇关于通过ssh或https自动访问git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:34