« Blog Home

Learn More About Git Submodules

Last update: 2/27/2022

In this article, we want to tell you how to control versions of complex systems using git submodules.
Let’s have a look at the following imaginary example. 

Our company has developed a system named Car, which consisted of 3 subsystems: Motor, Steering, and Transmission.

vehicle git submodules by pixabay

Each subsystem has been developed in a separate Git repo and progressed from one version to another. 

Up to a certain stage, each subsystem could be tested independently, but in the end, we needed to assemble and test the whole Car.

How could we know with what version of each subsystem would we test it? Where would it be recorded?

This is where git submodules came to our help. We created a fourth repo, Car, and included all three subsystem repos as submodules.

We did not copy files to the Car repo. The Car repo contained only pointers to specific commits of each of the three subsystem repos.

To understand it better, let’s look at the following table:table1 On July 1, 2020, we created commit 1.0 in repository Car, which contained links to commit 1.1 in Motor, commit 1.3 in Steering and commit 1.4 in Transmission, so when we tested version 1.0 of Car, we knew exactly what version of each subsystem was used. 

After two months…

Two months had passed, and version 2.0 was developed for each subsystem. However, we didn’t want to test all changes at once. We decided to start with Transmission. Thus we created a new commit in Car, 1.1, which had version 2.0 of Transmission and no changes in other subsystems.

After successfully testing Car with version 2.0 of Transmission, we created commit 1.2 in Car, with version 2.0 of Motor, and tested it. And lastly, we created and tested commit 2.0 of Car, with all subsystems at version 2.0.

Using submodules for access control

If you are using a web-based Git server like GitLab, GitHub, Bitbucket or Azure DevOps, you can use submodules to control access to your software. In the above example, if Motor, Steering and Transmission are being developed by subcontractors, you can limit access of each subcontractor to its repository, and give full access to all repositories to Car integrators only.


Using Git submodules, at each test of Car we knew what versions of subsystems were used. Moreover, since all commits were saved in the Car repo, now we can replay any of the previous tests exactly as they were run originally.

Note: Those of you who have used or still are using ClearCase UCM may remember that it has similar functionality, named composite baseline. It also allows you to manage projects comprising multiple repositories.

We provide training of git, Advanced git, GitLab, GitLab CI, Bitbucket, GitHub, git + Kubernetes and software development workflows.
Contact us for more information: git@almtoolbox.com or call us +972-722-405-222 (International) / 866-503-1471 (US & Canada)

Related Links: