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

Viewed 72913

I really like this command to fetch a repo with submodules:

git clone git@github.com:my_user/my_repo.git --recursive

However, the submodules are all set to "no branch" when they arrive, and I have to manually checkout master on each and every one. Is there a way to recursively pull submodules and automatically set the branch to master?

5 Answers

As already answered

git submodule foreach --recursive git checkout master

does the job for the branch master.

But if it is a branch that is not present in all of the submodules one can use

git submodule foreach --recursive "git checkout branchname || true"

Otherwise the command will fail on the first repo not having the specified branch.

Related