If you are using submodules in a git repo, you might find yourself sometimes wanting to execute a command recursively in the primary/parent repo as well as all submoduls. Well, I found myself in that position, and I'm writing this for my future self.
The most basic approach to this is to use git submodule foreach <command>
, where <command>
can be any git command, or a shell command including commands such as git status .
or git checkout main
This basically loops through all submodules and performs the command specified, but it does not execute this command in the root repo.
Well, that is luckely easy too. Simply add the keywoard --recursive
as following:
git submodule foreach --recursive