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
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.
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 .
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With