What Are Git Submodules and How Do They Work?

A Git submodule embeds one Git repository inside another as a subdirectory, pinned to a specific commit.

Published September 28, 2026

A Git submodule embeds one Git repository inside another as a subdirectory, pinned to a specific commit.

Key points

  • Useful for including a shared library or dependency as its own independently versioned repository
  • git submodule add <url> path adds a new submodule; git submodule update --init --recursive fetches submodule content after cloning
  • A submodule points at an exact commit, not a branch — it must be explicitly updated to pull in the latest changes

Example

git submodule add https://github.com/user/lib.git vendor/lib
More Git articles