'git submodule update --init --recursive' VS 'git submodule foreach --recursive git submodule update --init' 'git submodule update --init --recursive' VS 'git submodule foreach --recursive git submodule update --init' git git

'git submodule update --init --recursive' VS 'git submodule foreach --recursive git submodule update --init'


git submodule update --init --recursive

The submodule update command will recurse into the registered submodules, update and init (if required) them and any nested submodules within.

git submodule foreach --recursive git submodule update --init

foreach will evaluate the command in each checked out submodule. So it will update and init (if required) each submodule and any nested submodules within due to --recursive.

So in the end, both commands will achieve the same thing.Simply the execution differs, the first command won't step into each directory to execute the command.


In my experience, the first one works. The second one does nothing.

For a project like eclipse.platform.releng.aggregator to initialize submodules so you can build, you need to clone all the child repos:

 git submodule update --init --recursive


There exist differences!

 git submodule update --init --recursive

will register direct dependent submodules and clone them down, then go into next depth, register submodules and clone them recursively. Finally, all directly or indirectly dependent submodules will be registered and cloned from the remote.If there exists cyclic dependency, this command will never terminate.

git submodule foreach --recursive git submodule update --init

This command follows the template:

git submodule foreach --recursive "your command"

which means that firstly, "git submodule foreach --recursive" will generate a submodules set, then in each submodule, your command gets executed. However for a initial project without executing "git submodule init" and then "git submodule update", "git submodule foreach --recursive" will be empty, so "your command" won't take place at all.