Submodule shadow copy (shallow)
When to use
Use a shadow copy for every submodule: shallow clone, minimal history. Apply when adding or configuring submodules in this repo.
Rule
All submodules must be shallow. Do not add or leave a submodule with full history.
Adding a new submodule
- •Add the submodule as usual:
bash
git submodule add <url> <path>
- •Immediately set shallow in
.gitmodulesfor that submodule:- •Open
.gitmodulesand find the[submodule "…"]section for the new path. - •Add
shallow = truein that section (same level aspathandurl).
- •Open
Example section after add:
ini
[submodule "src/3rdparty/some-lib"] path = src/3rdparty/some-lib url = https://github.com/org/some-lib.git shallow = true
- •Optionally make the current clone shallow (if the repo was already cloned with full history):
bash
cd <submodule-path> git fetch --depth 1 git checkout <desired-ref> cd -
Existing submodules
- •In
.gitmodules, every[submodule "…"]section should containshallow = true. - •If one is missing, add
shallow = trueso clone/update uses a shadow copy.
Updating submodules
- •
git submodule update --init --recursiverespectsshallow = truein.gitmodulesfor initial clone. - •Do not run commands that explicitly fetch full history for a submodule (e.g.
git fetch --unshallowin the submodule) unless the user asks.
Verification
- •
.gitmoduleshasshallow = truefor every submodule. - •After a fresh clone,
git submodule update --init --recursiveproduces minimal submodule history.