In Git, a submodule is a way to include a separate repository in the main project and keep track of changes. While working on a large project, developers work on different submodules. They need to pull submodules because it permits them to keep the repository as a part of another Git repository and keep track of changes made to the submodule.
This article will explain the procedure to pull the Git submodule after cloning the project from GitHub.
How to Pull Git Submodules After Cloning Project From GitHub?
To pull the Git submodule after cloning the project from GitHub, first, navigate to the local repository and add the submodule to it. Then, run the “git submodule update –recursive” command to pull the Git submodule. Alternatively, switch to the submodule and execute the “git pull –recurse-submodule” command.
Step 1: Navigate to Desired Repository
First, use the below-provided command and redirect to the required local repository:
Step 2: Create/Add Submodule
Then, write out the “git submodule add” command along with the desired remote repository’s URL to add the submodule:
Step 3: Verify New Submodule
Next, ensure whether the submodule has been added or not by using the given-provided command:
According to the given output, the “Demo_SubMod” submodule has been added:
Step 4: Pull Git Submodule
In order to pull a Git submodule, type out the “git submodule update” command with the “–recursive” flag:
Here, the “–recursive” flag is used to update the submodule recursively.
Step 5: Navigate to Submodule
Now, utilize the following command and redirect to the submodule:
Step 6: View Submodule’s Content
Lastly, enter the “ls” command to list the submodule’s content:
It can be observed that the content of the GitHub repository has been pulled to the submodule:
Moreover, the user can also utilize the “git pull –recurse-submodule” command in the submodule repository to perform the pull operation:
The below-provided screenshot indicates that the submodule is already up to date:
We have explained the method to pull the Git submodule after cloning the project from GitHub.
Conclusion
To pull Git submodules after cloning the project from GitHub, various command is used, such as the “git submodule update –recursive” command can be executed in the root repository, and the “git pull –recurse-submodule” can be utilized in the submodule repository. This article explained the procedure to pull a Git submodule after cloning the project from GitHub.