Skip to content

Git submodules

Various

Update all submodules

git submodule update --remote --recursive

Iterate over submodules

Run a command in its own shell for each submodule in the current repository. The shell will be run in the main directory for the submodule.

git submodule foreach 'git branch --show-current'

In my Zsh setup, I have a custom prompt that shows git status information with a helper function in its theme.

I can use this to show this prompt information for each submodule:

git submodule foreach -q 'zsh -li -c "print -P -- \$name\ \$(prompt_git)\$(prompt_end)"'