Add a Git submodule and track a pinned version of another repository

domain: git-scm.com · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Run `git submodule add <repository-url> <path>` from your superproject root; this clones the repo into <path>, stages it in the index, and records the URL in a `.gitmodules` file.
  2. For a relative URL to a sibling repo, use `../foo.git` (not `./foo.git`) — Git resolves submodule URLs like relative directories.
  3. Commit the superproject change: `git commit -am "add submodule"` — this records the exact commit SHA the submodule is pinned to, plus the `.gitmodules` entry.
  4. On a fresh clone, run `git submodule update --init` (or `git clone --recurse-submodules <url>`) to fetch and check out the pinned submodule commits; `--recursive` handles nested submodules.
  5. Set the default remote-tracking branch a submodule follows with `git submodule set-branch -b <branch> <name>`, and change its URL later with `git submodule set-url <name> <newurl>` (which also syncs the remote config).
  6. Check per-submodule status with `git submodule status` (a leading `-` means not initialized, `+` means the checked-out commit differs from the index SHA).
  7. To detach a submodule permanently, use `git rm <path>` (after `git submodule deinit -f <path>` for older workflows) rather than only editing `.gitmodules`.
  8. Official docs: https://git-scm.com/docs/git-submodule

Known gotchas

Related routes

Initialize and sync submodules in a fresh clone (git submodule update --init --recursive)
git-scm.com · 7 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans