Git submodules
Submodules in git are used for including a repo inside another repo. The intended use case is when you want to maintain a specialized branch of another repo within a repo. That way, you can keep the commits separate between the projects, but still push joint commits between the projects.
A nice use case other than this is the following.
Let’s say you want to make cloning and using repo A super easy.
A depends on repo B, but no other code is expected to.
For example, you want to have vim-plug
included in your configuration repo.
You know vim-plug
will not need to be shared with any other project, so why not keep it in dotfiles
?
Including it as a submodule allows you to clone A (dotfiles
) and B (vim-plug
) at the same time, and even specify a commit of B for posterity.
Basics on getting started
Cloning the repo as a submodule:
git submodule add <remote>
Now you can navigate to that repo and treat it as a separate repo from the containing one.