Need to include another Git repository inside yours? git submodule embeds a repo as a sub-directory, pinned to a specific commit. A repo within a repo.
Your main project is a restaurant app. It uses a
shared UI library and a recipe engine
that are separate repos maintained by other teams.
Instead of copy-pasting, you link them as
submodules — each one
tracks its own repo and stays pinned to a specific version.
Each submodule is its own Git repo with its own commits.
Your main repo just stores a pointer (commit hash) to
the exact version you want.
Key rule: after cloning, always run
git submodule update --init --recursive
to actually download the submodule content.
Modern alternative: many teams prefer package managers (npm, pip) for dependencies. Use submodules when you need to develop the dependency alongside your project.