Chapter 15. Submodules
Itâs common to have a lot of applications that rely on one utility library or set of libraries. In such situations, you want each of your applications to be developed, shared, branched, and merged in its own Git repository, either because thatâs the logical unit of separation or perhaps because of code ownership issues.
But dividing your applications in this way creates a problem. Each application relies on a particular version of the shared library, and you need to keep track of exactly which version. If someone upgrades the library by accident to a version that hasnât been tested, they might end up breaking your application. Furthermore, the utility library isnât developed all by itself; usually people are tweaking it to add new features that they need in their own applications. Eventually, they want to share those new features with everybody else writing other applications; thatâs what a utility library is for.
Several strategies are commonly used in an attempt to address this issue, including conducting partial checkouts, importing dependent code directly into the project, or even copying the dependent project as a subfolder in the project. But these are not elegant solutions; in fact, some people view them as âhacks.â
Git addresses this issue with submodules. A submodule is simply a project that is part of your Git repository but also exists independently in its own source control repository. Gitâs mechanism for indicating a direct reference ...
Get Version Control with Git, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.