Cloning a Project With Submodules
Learn to clone a project with submodules with the help of a “recursive” flag.
We'll cover the following
Submodules have a special status within Git repositories. Since they are both included within a repository and at the same time reference as a remote repository, a simple clone will not check out the included submodule. Let’s show that:
1   cd ../..
2   git clone bob_repo bob_repo_cloned
3   cd bob_repo_cloned
4   ls -1
5   cd alicelib
6   ls
7   cd ..
alicelib's content is not there. Confusingly, git submodule status gives you a little clue of what’s going on here.
8   git submodule status
The dash (or minus sign) at the front indicates the submodule is not checked out. Only by running a git submodule init and a git submodule update can you retrieve the appropriate submodule repository:
9   git submodule init
10  git submodule update
11  git submodule status
The submodule status has no dash, and a commit ID has been added to the output (969b840…).
The git clone --recursive flag#
Fortunately, there is an easier way. You can clone the repository with a --recursive flag to automatically init and update any submodules (and submodules of those submodules ad infinitum) within the cloned repository:
12  cd ..
13  git clone --recursive bob_repo bob_repo_cloned_recursive
In case you’re wondering if you clone a repository with --recursive and there are no submodules, then Git does not complain.
