Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 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