gitgit-submodulesgit-subtree

Differences between git submodule and subtree


What are the conceptual differences between using git submodule and subtree?

What are the typical scenarios for each?


Solution

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


    Plus, as noted by philb in the comments, git subtree is a contrib/, as opposed to git submodule (core command)