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

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


当前回答

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

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层深处。请允许我向您展示它是如何运作的:

其他回答

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

$ 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 submodule init 
git submodule update

试试看:

git clone --recurse-submodules

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

1.git子模块初始化2位子模块更新

或者可能git存储-ugit拉动原点主机数字存储p

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

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