Submodules

Updated

October 30, 2026

Submodule Mechanics: Add, Update, Clone

After this page you can attach another Git repository at a path and record which commit it should be.

Clone a superproject

git clone --recurse-submodules <url> desk-api
# or after a plain clone:
git submodule update --init --recursive

Without --recurse-submodules / update --init, the path exists as an empty directory.

Update the pin

cd src/desk-lib
git fetch
git switch main
git pull --ff-only
cd ../..
git add src/desk-lib
git commit -m "chore: bump desk-lib"

The parent records a new gitlink hash. Pulling the parent does not move the submodule until git submodule update.

Pitfalls

  • Committing in the submodule and forgetting to push it: the parent points at a hash nobody else can fetch.
  • Editing files in src/desk-lib while detached: git switch -c in the submodule first.
  • Nested submodules: --recursive on clone and update.

If the team is small and desk-lib changes with desk-api every day, a monorepo (chapter 15) or a copy may hurt less. Submodules shine when the nested project has its own release cycle.