A Git submodule is a Git repository embedded inside another Git repository, where the parent repo stores a pointer to a specific commit in the submodule rather than copying all of its history. It is useful when you want to include shared code or a dependency while keeping it in a separate repository.

Quick Scoop

  • The main repository is often called the superproject.
  • The submodule is tracked by a commit hash , so it stays pinned to a specific version.
  • Git also creates a .gitmodules file to record the submodule’s path and URL.

Why people use it

  • To reuse code across multiple projects without duplicating it.
  • To keep a dependency separate while still including it in your project.
  • To make it easier to control exactly which version of that dependency your project uses.

Important behavior

  • Submodules do not automatically follow the latest branch tip; they stay on the commit you recorded.
  • If the submodule changes upstream, you usually need to update it explicitly in the parent repository.
  • This can be powerful, but it can also feel a bit more manual than using a plain dependency manager.

Simple example

If your app depends on a shared UI library, you can add that library as a submodule. Your app will then point to one exact version of the library, so builds stay predictable.

If you want, I can also show the basic commands for adding, cloning, and updating a Git submodule.