0

On the question:

  1. How to correctly call a git submodule symlinked?

Was figured it out it is necessary to checkout the git submodules to their default branch when a git clone --recursive is performed, but how to do that?

I tried searching and found this other question:

  1. Easy way pull latest of all submodules

Suggesting to use the command git clone --recurse-submodules but after cloning the repository its submodule still not checkout on their default branches.

Evandro Coan
  • 8,560
  • 11
  • 83
  • 144

2 Answers2

2

git submodule foreach git checkout master

phd
  • 82,685
  • 13
  • 120
  • 165
2

You can use git submodule foreach to run an arbitrary command in each submodule. The --recursive flag will recurse through the submodules' submodules. git remote show [name-of-remote] will say which branch [name-of-remote] currently has active. Combining them with a few other tools to clean up git remote show's output gives:

git submodule foreach --recursive "git checkout $(git remote show origin | grep 'HEAD branch' | sed 's/.*: //')"

This is, of course, dependent on already having cloned the submodules.

8bittree
  • 1,769
  • 2
  • 18
  • 25
  • Thanks! I think I can do the command `git clone --recursive https...; git submodule foreach ...`, then it should clone everything and checkout their master. – Evandro Coan Jun 16 '17 at 18:04
  • Is there a solution platform independent or a Windows version of it? If I run this command on Windows, it would not have available the `grep 'HEAD branch' | sed 's/.*: //'` part. – Evandro Coan Jun 16 '17 at 18:10
  • 1
    @user I believe `grep` and `sed` are included in the standard Git for Windows installation, though depending on which options you selected during installation, you may need to use git bash rather than cmd. – 8bittree Jun 16 '17 at 18:13