How to Clone Including Git Submodules
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 <remote-repo-url>
Initializing a submodule
The second step is setting up the submodule like this:
git submodule init
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
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
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:
How to Clone Including Git Submodulesgit 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.