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

后端 未结 5 1043
失恋的感觉
失恋的感觉 2020-12-04 10:45

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

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

However, the submodule

5条回答
  •  渐次进展
    2020-12-04 11:39

    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.

提交回复
热议问题