Gitflow
🧩Add a SubmoduleMedium+500 XP
Scenario reference

Add a Submodule: the situation, step by step

The situation

Your app needs to pin a fork of `shared-ui` at an exact commit. Vendoring is messy — a submodule is correct.

A submodule is two things in the parent repo: a `.gitmodules` entry and a pinned pointer. Real `git submodule add` also clones the sub-repo, which this browser engine cannot do — so you write the record by hand and commit it.

Medium · 4 steps · +500 XP

What you will practice

This scenario walks through 4 steps, in order:

  1. 01Write the .gitmodules record `git submodule add` would create
  2. 02Stage the record
  3. 03Commit the submodule pointer
  4. 04Confirm what the parent repo now tracks
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Write the .gitmodules record `git submodule add` would create
    echo "[submodule vendor/shared-ui] url = git@github.com:you/shared-ui.git" > .gitmodules
  2. 2. Stage the record
    git add .gitmodules
  3. 3. Commit the submodule pointer
    git commit -m "deps: add shared-ui submodule"
  4. 4. Confirm what the parent repo now tracks
    git ls-files

Key takeaway

`.gitmodules` names the URL and path; the tree entry pins the exact commit. `git submodule add` writes both and clones the sub-repo in one go, and clones need `--recurse-submodules` to populate it.