Git Cheat Sheet · Submodules and LFS
Initialize and update submodules
git submodule update --init
A submodule is a Git repository stored in a folder of another repository, pinned to a specific commit. After a clone, its folder is empty: git submodule update --init --recursive downloads it at the commit recorded by the parent repository.
What it does
Gets the nested repositories at the commit recorded by the parent repository.
A use case
You just cloned a project with a library provided as a submodule: its folder is empty.
On the command line
git submodule update --init --recursive- Initializes and fetches all submodules, including nested ones.
git submodule add <url> <folder>- Adds a submodule.
git submodule update --remote- Moves submodules forward to the last commit of their branch.
git submodule status- Each submodule's commit.
git config --global submodule.recurse true- Updates submodules on every pull or checkout.
In Merathon
- "Submodules" section of the left panel: the "+" initializes and updates them all.
- Right-click a submodule to update it alone or open it in a new tab.
Frequently asked questions
Why is the submodule's folder empty?
A clone does not fetch submodules by default. Run git submodule update --init --recursive, or clone with --recurse-submodules.
Why does a submodule appear modified in git status?
Its current commit is no longer the one recorded by the parent. Commit the new commit in the parent, or run git submodule update to go back to the recorded commit.