What is the difference between a Git submodule and a subtree, and what are the trade-offs?
Last updated
A submodule keeps the child as a separate repo referenced by a commit pointer: small parent and easy upstream pushes, but extra commands and easy desync.
A subtree (
git subtree) copies the child's files (and optionally history) into a subdirectory: one-shot clones and no special commands, but a larger repo and harder upstream pushes.Choose submodules for strict separation and frequent upstream contributions. Choose subtrees for simple consumption.
- https://devup.top/archives/yi-ge-guan-yin-yi-ge-guan-chao-submodule-he-subtree-dao-di-chai-zai-na
- https://medium.com/@Spritan/git-submodule-vs-git-subtree-quick-technical-overview-92ae10119145
- https://saeed-vayghan.github.io/blog/git-submodule-vs-subtree.html
- https://www.grizzlypeaksoftware.com/library/git-submodules-and-subtrees-when-to-use-each-naksp03o
- https://www.grizzlypeaksoftware.com/library/git-submodules-and-subtrees-when-to-use-each-ck193k9t
- https://www.geeksforgeeks.org/git/git-subtree-vs-git-submodule/
- https://www.geeksforgeeks.org/git/git-subtree/
- https://git-scm.com/book/en/v2/Git-Tools-Submodules