Home·Terminal commands

git submodule

git

Usage

git submodule update --init --recursive

Pins another repository at one commit inside yours; a plain clone leaves the folder empty until update --init, and the parent tracks a commit, not a branch.

Common flags

FlagMeaning
add <url> <path>pin another repository at a path
update --initfill in a submodule folder that a clone left empty
--recursivego into submodules of submodules
update --remotemove the pin to the tip of the tracked branch
statusthe commit each submodule sits at
deinit <path>unregister it
foreach <cmd>run a command in each one

Examples

git submodule update --init --recursive

the command that fills empty submodule folders after a clone

git submodule add https://github.com/x/lib.git vendor/lib

adds a dependency as a submodule

git submodule update --remote

updates the pinned commit to the branch tip

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git submodule do?

Pins another repository at one commit inside yours; a plain clone leaves the folder empty until update --init, and the parent tracks a commit, not a branch.

Q. How do I type it?

git submodule update --init --recursive — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-submodule