Differences between git submodule and subtree
git, git-submodules, git-subtree
Solution
- submodule is a better fit for component-based development, where your main project depends on a fixed version of another component (repo). You keep only references in your parent repo (gitlinks, special entries in the index)
What if I want the links to always point to the HEAD of the external repo?
You can make a submodule to follow the HEAD of a branch of a submodule remote repo, with:
o `git submodule add -b <branch> <repository> [<path>]`. (to specify a branch to follow) o `git submodule update --remote` which will update the content of the submodule to the latest HEAD from `<repository>/<branch>`, by default `origin/master`. Your main project will still track the hashes of the HEAD of the submodule even if `--remote` is used though.
- subtree is more like a system-based development, where your all repo contains everything at once, and you can modify any part. See an example in this answer.
Plus, as noted by philb in the comments, `git subtree` is a `contrib/`, as opposed to `git submodule` (core command)
Problem
What are the conceptual differences between using git submodule and subtree? What are the typical scenarios for each?
Related problems
- SVN:externals equivalent in Git?
- How do I add files in Git to the path of a former submodule?
- Force Git submodules to always stay current
- Git submodule is in "detached head" state after cloning and submodule update
- git submodule tracking latest
- Alternatives to Git Submodules?
- What is Component-Driven Development?
- Vendor Branches in Git