Working With Git Repositories: Submodules

Let's learn how to work with git repositories by git submodules.

Many projects rely on Git as a version control system. Assuming that our project and external library are both using it, is there some kind of Git magic that would allow us to link these repositories together? Can we build a specific (or latest) version of the library as a step toward building our project? If so, how?

Providing external libraries through Git submodules

One possible solution is to use a mechanism built into Git called Git submodules. Submodules allow a project repository to use other Git repositories without actually adding the referenced files to the project repository. They work similarly to soft links—they point to a specific branch or commit in an external repository (but we need to update them explicitly). To add a submodule to our repository (and clone its repository), execute the following command:

Get hands-on with 1400+ tech skills courses.