Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git
communitycreator

How to use Git submodules

Anjana Shankar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Git submodules are a powerful way to use git as an external dependency management tool. It is basically a way to embed a repository into another. When you add a submodule in Git, the code of the submodule does not get added to the main repository (only certain information about the submodule does); instead, it simply adds a reference to the submodule. This is analogous to the soft link you may have created in your file system.

Advantages of using submodules

  1. Easy separation of code into different repositories.
  2. The submodule can be added into multiple repositories, allowing for easy management.

Adding a submodule

First, change the directory to the git repository that you want to add the submodule.

git submodule add <submodule_repo_path>

When you do,

git status

you will see that a .gitmodules file has been added, along with the directory corresponding to your git submodule repository.

The .gitmodules file contents would be look like:

[submodule "<submodule_name>"]
path = <submodule_directory>
url = <submodule_repo_path

Now you can,

git add

these two and push it to your remote repo.

On the remote side, you should see a symlink from this repository to the submodule repository.

RELATED TAGS

git
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring