What is git submodule?
Answer
Git submodules allow you to include one Git repository as a subdirectory inside another. The parent repo stores a reference (specific commit) to the submodule repo — not the content itself. When you clone the parent, submodules are empty until initialized. Adding a submodule: git submodule add https://github.com/other/lib.git vendor/lib — creates .gitmodules config file and adds the submodule directory. The parent repo records the exact commit of the submodule (pinned version). Cloning with submodules: git clone --recurse-submodules url or after cloning: git submodule update --init --recursive. Update to latest: git submodule update --remote. Working in a submodule: cd into the submodule, work normally (it's a regular Git repo), commit, then back in parent: git add submodule/path && git commit to update the tracked commit. Remove a submodule: git submodule deinit vendor/lib && git rm vendor/lib. Drawbacks: complex workflow, easy to forget updating, confusing for new contributors. Alternatives: git subtree (merges history), language package managers (npm, Maven, pip), monorepo tools. Use submodules when you need to pin to specific commits of a shared library.