Differences between git submodule and subtree

Solution 1:

submodule is link;

subtree is copy

Solution 2:

  • 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)