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

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


当前回答

尝试在git存储库中包含子模块。

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

or

git clone --recurse-submodules

其他回答

试试看:

git clone --recurse-submodules

假设您已经将子模块添加到父项目中,它会自动引入子模块数据。

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

git submodule init 
git submodule update

您可以从github复制克隆url

然后使用:git clone—递归

如何“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存储库。

如果子模块是私有子模块,您可以使用凭证存储,这样它也可以递归地克隆其私有子模块。

USER=${GITHUB_ACTOR}
TOKEN=${{ secrets.JEKYLL_GITHUB_TOKEN }}

git config --global credential.helper store
echo "https://${USER}:${TOKEN}@github.com" > ~/.git-credentials

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

我用它来克隆我的子模块,其中私有模块位于第5层深处。请允许我向您展示它是如何运作的: