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

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


当前回答

克隆存储库时,可以使用--recursive标志。此参数强制git克隆存储库中所有已定义的子模块。

git clone --recursive git@repo.org:your_repo.git

克隆后,有时子模块分支可能会发生更改,因此在其之后运行以下命令:

git submodule foreach "git checkout master"

其他回答

如果是一个新项目,你可以这样做:

$ git clone --recurse-submodules https://github.com/chaconinc/YourProjectName 

如果已安装,则:

$ cd YourProjectName (for the cases you are not at right directory) 
$ git submodule init
$ git submodule update

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

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

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

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

更新所有子模块的代码

git submodule update --recursive --remote

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

git submodule init 
git submodule update

您可以从github复制克隆url

然后使用:git clone—递归