01
Overview
Submodules embed one repo inside another. Useful for shared libraries. Cloned separately. Update with git submodule update. Can be complex; consider monorepo or package manager instead.
bash
git submodule add https://github.com/lib/foo libs/foo
git submodule update --init --recursive
git submodule update --remote # update to latest
# Clone with submodules
git clone --recurse-submodules url
# Remove
git submodule deinit libs/foo02
Best Practices
Prefer package manager or monorepo over submodules. Submodules add complexity (detached HEAD, sync issues). Use --recurse-submodules when cloning. Update with --remote. Use git subtree as alternative. Document submodule workflow for team.)
Ready to try Git Submodules?
Visit the official site for the latest version and full documentation.
Visit Git Submodules