Chapter 8. Vendoring dependencies as submodules

 

This chapter covers

  • When submodules are useful
  • Adding a submodule to a repository
  • Viewing the status of the submodules in a repository
  • Updating and initializing all submodules in a repository
  • Running a command in every submodule in a repository

In this chapter, you’ll learn how to maintain dependencies on other Git-based software projects within your own using Git submodules.

8.1. When are submodules useful?

Almost all software projects use other software projects as libraries or tools. For example, say you’re using Git and writing a desktop application in C++, and you want to communicate with a server that provides a JSON API. Rather than writing the JSON-handling code yourself, you find an open source project on GitHub that provides a library for accessing JSON APIs with C++. You want to include this open source library into your project and update it when new versions are released with bug fixes you need.

There are generally two approaches to handling other software projects (usually known as dependencies) and which versions work with your own software:

  • Write documentation for what other software projects are required, what versions they should be, and where they should be installed, so other developers building the project know how to set it up correctly.
  • Include the dependencies in the project’s repository so they’re always available to anyone when cloning the repository. This is known as vendoring the dependencies.

8.2. Summary