I have git repo which has nested submodules. What is the difference between below 2 commands?
git submodule update --init --recursive
git submodule foreach
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.