Cloning a Git repository with Sub modules

If you are a new collaborator who is joining the project, you’d start by running git clone command to download the contents of the repository. At this point, if you peek inside the sub-module folder, you’ll see nothing in there. Well, please don’t be surprised though. Git expects us to explicitly ask it to download the sub-module’s contents. For that you can use below commands:

For Git Versions 1.6.5 and later :

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

From Git Versions 1.9 and up to 2.12 :

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

Note: -j8 is an optional optimization flag that became available in version 2.8. It fetches up to 8 sub-modules at a time in parallel. Checkout man git-clone for more details.

For Git Versions 2.13 and Later :

git clone --recurse-submodules -j8 <project url>

With version 2.13 of Git and later, –recursive flag has been deprecated and –recurse-submodules flag should be used instead.

If the repository is already cloned or if you are using an old git version you can do as shown below:

git submodule update --init --recursive

Ciao 👋👋👋

Was this helpful?
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0