All chapters in this track
- 011. The Mental Model
- 022. Essential Setup
- 033. Core Daily Workflow
- 044. Branching
- 055. Merging & Conflict Resolution
- 066. Rebasing
- 077. Remote Repositories
- 088. Stashing
- 099. Undoing Things
- 1010. Tagging & Versioning
- 1111. Cherry-Pick
- 1212. Git Bisect & Blame
- 1313. Git Hooks
- 1414. Submodules
- 1515. Team Workflows
- 1616. Power Commands & Aliases
- 1717. Reflog: The Safety Net
- 1818. Practice Tasks
- 19Quick Reference Cheatsheet
Chapter 14 of 19
14. Submodules
Submodules let you embed one Git repo inside another — useful for shared libraries or vendor code.
# Add a submodule
git submodule add https://github.com/org/lib.git libs/lib
# Clone a repo that has submodules
git clone --recurse-submodules <url>
# If you already cloned without --recurse-submodules
git submodule init
git submodule update
# Update submodule to latest remote commit
git submodule update --remote libs/lib
# Remove a submodule
git submodule deinit libs/lib
git rm libs/lib
rm -rf .git/modules/libs/lib
Warning: Submodules add complexity. Consider alternatives:
- Package managers (
npm,pip,cargo) for dependencies - Git subtree for simpler vendoring