How to Clone Including Submodules

  1. Steps to cloning repository including submodules
    1. Cloning project
    2. Initializing a submodule
    3. Updating the submodule
  2. The git init and git clone Commands

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:

1. Cloning project

First, you should git clone the project:

git clone

2. Initializing a submodule

The second step is setting up the submodule like this:

submodule init

3. Updating the submodule

And the final step is updating the submodule:

git submodule update

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

git submodule update --init
If you do not init, 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 URL git://github.com/foo/example.git
cd example

With version 2.13 and later, you can use --recurse-submodules instead of --recursive

git clone --recurse-submodules -j8 git://github.com/foo/example.git
cd example
-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 --recursive -j8 git://github.com/foo/example.git
cd example

With version 1.6.5 and later, you can invoke:

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

For cloned repositories or older versions, execute:

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

The git init and git clone Commands

The git clone 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 git clone 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 commitment of snapshots.

The git init and git clone commands are usually confused with each other. The git clone command is dependant on git init and creates a copy of a repository that already exists.


Do you find this helpful?

Related articles