如何克隆git存储库,以便它也克隆其子模块?

运行gitclone$REPO_URL只会创建空的子模块目录。


当前回答

如何“git克隆”回购,包括其子模块?

(我把它作为一个独立的答案,因为我认为这在git中很重要)

可悲的是,但在很多情况下,那些不太知情的克隆人会错过外在的东西:

vc大便(https://github.com/dirk-thomas/vcstool)数字子报表(https://github.com/ingydotnet/git-subrepo)git链接(https://github.com/chronoxor/gil).gitsvnextmodule(由smartgit处理)。git外部(https://github.com/develer-staff/git-externals)git x模块(https://gitmodules.com/)等等

作为备份,无法创建裸克隆(--bare)+完全递归(--recursive)来镜像(--mirror)所有引用(而不仅仅是所有外部引用):使用--recursive和--bare克隆git存储库

因此,对于git,没有一种内置的方法可以完全接受外部依赖关系。这意味着没有一种方法可以完全备份任何随机git存储库。

其他回答

我在GitHub存储库中遇到了同样的问题。我的帐户缺少SSH密钥。该过程是

生成SSH密钥向GitHub帐户添加新的SSH密钥

然后,您可以使用子模块克隆存储库(gitclone--递归YOUR-git-REPO-URL)

or

运行gitsubmodule init和gitsubmodule update以获取已克隆存储库中的子模块。

试试这个。

git clone -b <branch_name> --recursive <remote> <directory>

如果在分支中添加了子模块,请确保将其添加到clone命令中。

在填充子模块之前,您必须做两件事:

git submodule init 
git submodule update

使用此命令克隆所有子模块的repo

git clone --recurse-submodules git@gitlab.staging-host.com:yourproject

更新所有子模块的代码

git submodule update --recursive --remote

如果子模块被添加到分支中,请确保将其包含在克隆命令中。。。

git clone -b <branch_name> --recursive <remote> <directory>