Cloning a Repo with Submodules
Cloning a Repository with Submodules
When you clone a repository that contains submodules, Git will only download the main repository, not the submodules. To get the submodules as well, you need to follow these steps:
- Clone the main repository:
git clone https://example.com/main-repo.git
- Initialize the submodules:
cd main-repo
git submodule init
- Update the submodules:
git submodule update
Alternatively, you can combine the init
and update
steps into a single command:
git clone --recurse-submodules https://example.com/main-repo.git
This will automatically initialize and update the submodules when you clone the main repository.
Verifying Submodule Status
After cloning a repository with submodules, you can check the status of the submodules using the following command:
git submodule status
This will show the current commit of each submodule and whether it matches the commit recorded in the main repository.
Updating Submodules
If the submodules have been updated in the remote repository, you can update them in your local repository using the following command:
git submodule update --remote
This will update the submodules to the latest commits specified in the main repository.
graph TD
A[Clone Main Repo] --> B[Initialize Submodules]
B --> C[Update Submodules]
A --> D[Verify Submodule Status]
D --> E[Update Submodules]