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

Manish picture Manish · Jun 5, 2014 · Viewed 68.5k times · Source

I have git repo which has nested submodules. What is the difference between below 2 commands?

git submodule update --init --recursive

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

Answer

Martin picture Martin · Feb 13, 2015
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.