« Blog Home

Learn More About Git Submodules

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 versions 2.0 were 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.

Conclusion

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: