How do I git clone --recursive and checkout master on all submodules in a single line?

After cloning the repository containing your submodules, the following command will checkout the master branch on all of these in one go:

git submodule foreach --recursive git checkout master

How about:

git submodule update --init --recursive

To initialize all submodules and submodules inside submodules. Not sure if this will checkout master though.


The question is why you checkout master. Your sub modules are pinned to a specific sha - that's also why the sub module clones are fixed to that specific commit. By not pointing to a specific sha an external repo could easily break your builds. Most definitely not what you want. Better update consciously. Builds should be reproducible and as fix as possible.