W3docs

How to Clone Including Git Submodules

Get answers to the problem of cloning the parent repository so as the submodule folder does not stay empty. Get several methods regarding the Git versions.

A problem may occur when the submodule folder stays empty in the process of cloning the parent git repository. In this tutorial, we are going to show you several ways of cloning the repository that will solve your problem.

Steps to Cloning Repository Including Submodules

Follow the 3 steps coming next to solve the problem:

Cloning project

First, you should git clone the project:

git clone

git clone <remote-repo-url>

Initializing a submodule

The second step is setting up the submodule like this:

git init submodule

git submodule init

Updating the submodule

And the final step is updating the submodule:

update git submodule

git submodule update

Or you can shorten the whole process by executing the following:

git submodule and update

git submodule update --init
Warning

If you do not run git submodule update, the submodule folder will stay empty.

But you can use other methods regarding the versions of Git.

Using Git 1.6.5 version or higher, you can execute a single line:

git clone recursive

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

With version 2.13 and later, you can use <kbd class="highlighted">--recurse-submodules</kbd> instead of <kbd class="highlighted">--recursive</kbd>

git clone recurse submodule

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

-j8 is an optional performance optimization available in version 2.8. It fetches up to 8 submodules in parallel.

From version 1.9 to 2.12, use the following:

git clone

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

With version 1.6.5 and later, you can invoke:

git clone

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

For cloned repositories or older versions, execute:

git clone repositories

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

The git init and git clone Commands

The <kbd class="highlighted">git clone</kbd> creates a clone or copy of an existing repository into a new directory. It is the most commonly used command which allows users to obtain a development copy of an existing central repository.

The <kbd class="highlighted">git clone</kbd> initializes a new repository in the team-project folder on the local machine and fills it with the contents of the central repository. Next, you can cd into the project starting modification of files, interaction with other repositories, and committing snapshots.

The git init and <kbd class="highlighted">git clone</kbd> commands are usually confused with each other. The <kbd class="highlighted">git clone</kbd> command is dependent on <kbd class="highlighted">git init</kbd> and creates a copy of a repository that already exists.