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

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


当前回答

在Git 2.13及更高版本中,可以使用--recurse子模块代替--recursive:

git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar

编者注:-j8是一种可选的性能优化,在2.8版中提供,并且一次并行获取最多8个子模块——参见man git clone。

Git 1.9版至2.12版(-j标志仅在2.8+版中可用):

git clone --recursive -j8 git://github.com/foo/bar.git
cd bar

在Git 1.6.5及更高版本中,您可以使用:

git clone --recursive git://github.com/foo/bar.git
cd bar

对于已克隆的repo或较旧的Git版本,请使用:

git clone git://github.com/foo/bar.git
cd bar
git submodule update --init --recursive

其他回答

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

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

[快速回答]

克隆父回购(包括一些子模块回购)后,请执行以下操作:

git submodule update --init --recursive

您可以从github复制克隆url

然后使用:git clone—递归

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

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

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

or

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

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

git submodule init 
git submodule update