Git Submodules - What, how and more
Understanding git submodules and its usage

Search for a command to run...
Understanding git submodules and its usage

No comments yet. Be the first to comment.
A few months ago, my product manager dropped something in the team channel. "We are adding an AI agent to the platform next quarter. It will handle follow-ups automatically." Just like that. One messa

f you’re diving into React, you’ve likely come across the useRef hook. But what exactly is useRef(), and how can it make your life easier? In this post we’ll cover what useRef is, walk through five

A bug that only happens for some users, that you can never reproduce, that isn't in your code. Welcome to the React + browser-translation crash — what causes it, why it's so sneaky, and the battle-tested one-file fix.

Upgrading a core production database is usually the stuff of dev nightmares. It often involves maintenance windows, scheduled downtime, and the looming fear of a botched migration. But what if you cou

We are moving into products that adapt, predict and react with real context. Designing only interfaces is not enough anymore. We are designing experiences that understand the user. Designers and digital agencies are now challenged to move beyond trad...

Engineering at JoBins
167 posts
Welcome to Engineering at JoBins — where we share the stories, insights, and lessons from building a world-class hiring platform. From system design and scalability to developer tools and team culture, our engineers write about the real challenges we solve every day. Whether you're a curious developer or a fellow builder, we hope our experiences inspire and inform your own engineering journey.
Git Submodules are a way to include the contents of one Git repository within another Git repository. They allow you to keep a Git repository as a subdirectory of another Git repository, while still maintaining its separate history and version control.
There are several reasons why you might want to use Git submodules:
To include external libraries or dependencies in your project.
To collaborate with other developers on a project that depends on a separate component.
To share code between multiple projects.
To keep your project's dependencies separate from the main codebase, or to use a specific version of a dependency that is not the latest release.
Here's how Git submodules work:
When you create a submodule, you specify the URL of the external repository that you want to include in your project.
Git stores the submodule as a reference to a specific commit in the external repository.
When you clone your repository, Git also clones the submodule and checks out the specified commit.
If you make changes to the submodule and commit them, Git records the new commit in your parent repository.
To use a submodule in your repository, you need to first add it using the git submodule command. For example, to add a submodule named lib located at https://github.com/example/lib.git, you would use the following command:
git submodule add <https://github.com/example/lib.git> lib
This will create a new directory in your repository called lib, and initialize it as a Git repository. It will also add a new entry to your repository's .gitmodules file, which records the URL of the submodule and its local path.
Once you have added a submodule to your repository, you can update it to the latest commit by using the git submodule update command. This will fetch the latest changes from the upstream repository and update the submodule's reference to the new commit.
If you want to make changes to a submodule, you can do so by checking out a branch and committing your changes as you would with any other repository. However, you will need to push your changes to the upstream repository separately, and then update the reference in the parent repository using git submodule update.
Using submodules can be a convenient way to manage external dependencies in your Git repository, but it's important to understand how they work and how to use them effectively. In particular, you should be aware that submodules are only updated when you explicitly run git submodule update, so it's important to stay on top of updates to ensure that your project is using the latest version of its dependencies.
Using Git submodules has some advantages and disadvantages compared to other approaches for managing external dependencies. Some advantages include:
Git submodules are version controlled, so you can track changes to the external repository over time.
Git submodules are easy to set up and use.
Git submodules allow you to keep your repository lightweight since you only need to include the submodule reference, not the entire external repository.
However, there are also some disadvantages to using Git submodules:
Git submodules can be confusing for new users.
Git submodules can be difficult to update.
Git submodules can make it harder to merge changes between branches.
Git official documentation
The GitHub Blog
Git Submodules Tutorial
In general, Git submodules are a useful tool for managing external dependencies in your projects. However, it's important to weigh the advantages and disadvantages before deciding to use them in your work.