In software development, it’s common to manage projects that depend on other projects. Git submodules are a powerful feature that allows you to include and manage external repositories within your main repository. This feature enables you to keep multiple repositories in sync and makes it easier to work on complex projects that rely on various codebases. This article will guide you through the concept of Git submodules, their benefits, and how to use them effectively.
What Are Git Submodules?
Git submodules are pointers to another repository at a specific commit. They allow you to include a separate repository within your main repository, maintaining a connection between the two. This means you can manage dependencies as part of your project without merging all the code into a single repository.
Benefits of Using Git Submodules
- Modularity: Keep your project modular by separating dependencies into distinct repositories.
- Isolation: Manage changes in external dependencies without directly affecting your main project.
- Version Control: Pin dependencies to specific versions, ensuring stability and consistency.
- Reusability: Reuse submodules across multiple projects, avoiding code duplication.
Use Cases for Git Submodules
- Large Projects: Split large projects into manageable components.
- Shared Libraries: Include common libraries shared across different projects.
- Third-Party Dependencies: Manage third-party code dependencies separately from your main codebase.
Adding Git submodules

Adding submodules in git
Here, we can see to add a submodule in the git repository we have used the command:-
git submodule add url_of_the_git_repository
The above command takes URL as a parameter that points to a repository on Github. Here we have added theÂ
Submodules-in-git as a submodule. This command will clone the submodule and after that, we can check the status of the git repository using the git status command.
Here we can see that using the below command git status as it shows us the two files that are .gitmodules and the submodules-in-git directory. Now let’s see the contents of the .gitmodules file. These commands are as depicted via terminal/ PowerShell in below media as follows:

Contents of .gitmodules
Cloning a GitHub repository having  .gitmodules
For Cloning the repository having submodules we have to use the following command: Â
git clone ---recursive url_of_the_github_repository

Cloning GitHub repository having submodules
Git init
It is used to copy the mappings from a  .gitmodules file to a ./.gitconfig file.  Moreover, it is very helpful when there are many
submodules present in a repository activate only specific submodules which are needed for working in the repository.

Using git submodule initÂ
Workflows in submodules
As soon as you initialize the submodules and update them within a parent repository now we can use them as a different repository that can have their own branches and history. So when we are creating some changes in the submodule it’s important to have a track on them and commit them properly. So let’s switch to our submodule here  Submodules-in-git

Adding and Committing files in the submodule
Now let’s move back to the parent repository of this submodule which is present in folder10 and let’s see the status of the parent repository. As we can see that now the parent repository is aware that some changes are made in the submodules Now if one wants to update this parent repository you can do so by using git add and git commit commands.

Using git status command in the parent repository
Similar Reads
Git Submodule
Git submodules allow you to keep a Git repository as a subdirectory of another Git repository. This is useful when you want to include external libraries or shared components within your project while maintaining their history and keeping them separate from your main repository. In this article, we
5 min read
Use of Submodules in GitHub
Submodules in GitHub provide a way to incorporate one Git repository into another as a subdirectory. This feature is especially useful for managing dependencies, reusing code across projects, and maintaining modular codebases. In this article, we will explore the concept of Git submodules, their ben
4 min read
How to Add Submodule in Git?
Git is a widely used distributed version control and source code management system. It effectively tracks changes to source code, enabling easy branching, merging, and versioning. In this article, we will explore the concept of Git submodules, their benefits, and best practices for integrating them
4 min read
Updating a Submodule in Git
Git submodules are a powerful feature that allows you to include and manage external repositories within your own Git project. This is particularly useful for managing dependencies or handling third-party libraries. However, keeping these submodules up to date can be a bit tricky. In this article, w
3 min read
Git Subtree vs. Git Submodule
Git Subtree and Git Submodule are both mechanisms in Git that allow you to incorporate external repositories into your own repository. They provide a way to manage dependencies and include code from other projects while keeping your repository organized and maintainable. Git Subtree: Git Subtree all
4 min read
Git Submodule Update
Git submodules are useful features when working on projects that involve external repositories or dependencies. They allow you to keep a Git repository as a subdirectory of another Git repository. However, managing and updating submodules can sometimes be tricky. In this article, we'll cover everyth
3 min read
Git - Index
In Git, the index, also known as the staging area, plays an important role in the version control process. It acts as an intermediary between your working directory and the repository, allowing you to prepare and review changes before committing them. This article explores the concept of the Git ind
3 min read
Undoing in Git
Undoing in Git means doing undo just like when we type something in any text editor and delete the same. After that, we think the text that we just deleted is needed, and then we use the undo operation to get back the old text. The same undoing in git is like doing undo in git. Common Scenarios for
6 min read
Git - Subtree
Managing large codebases with multiple dependencies or sub-projects can be a challenging task. Git, the popular version control system, provides several strategies for handling such cases. One effective solution is the use of Git Subtree. Git Subtree allows you to include a repository as a subdirect
4 min read
Git - Object Model
Git is a distributed version control system. At the heart of Git's powerful capabilities lies its object model. Understanding Git's object model is important for mastering its use and leveraging its full potential. This article will dive deep into the components of the Git object model, explaining h
6 min read