Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 296
Manish Avatar asked Jun 05 '14 10:06

Manish


People also ask

What is git submodule update -- init -- recursive?

git submodule update --init --recursive --remote - updates all submodules recursively along their tracking branches. Without the --remote , it'll reset the submodule working directories to the "right" commit for the parent.

How do I update a submodule in git recursive?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .

What does git submodule init do?

The git submodule init command creates the local configuration file for the submodules, if this configuration does not exist. If you track branches in your submodules, you can update them via the --remote parameter of the git submodule update command.

What is git submodule foreach?

This is taken from the manual: git help submodule : foreach Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables $name, $path, $sha1 and $toplevel: $name is the name of the relevant submodule section in .


1 Answers

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.

like image 57
Martin Avatar answered Sep 21 '22 01:09

Martin