Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between subprojects and submodules in Git?

Tags:

git

People also ask

What are submodules in git?

A git submodule is a record within a host git repository that points to a specific commit in another external repository. Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.

What is the advantage of using submodules?

The first important advantage to using submodules is that submodules allow you to keep the commit history of the component you're including in your project. Assuming the component you're adding is publicly available as a git repository, incorporating this component without the use of submodules presents a problem.

Should I use git submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.

What does git pull -- recurse submodules do?

If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.


A subproject is a generic term for one of three types of nesting:

  • Submodules provide semi-fixed references from the superproject into subprojects and are integrated into git. It is best used when the subproject:
    • is developed by someone else, is not under the administrative control of the superproject and follows a different release cycle.
    • contains code shared between superprojects (especially when the intention is to propagate bugfixes and new features back to other superprojects).
    • separates huge and/or many files that would hurt performance of everyday git commands.
  • Subtrees causes the subproject repository to be imported into the superproject's repository to be a native part of the repository with full history, typically in a specific subdirectory of the superproject.
  • Wrappers, which provide multi-repository management functionality to a superproject with associated subprojects.

Reference documentation