Reputation: 9418
On the question:
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:
Suggesting to use the command git clone --recurse-submodules
but after cloning the repository its submodule still not checkout on their default branches.
Upvotes: -1
Views: 363
Reputation: 3212
git clone --recursive --branch develop https://github.com/aem-design/aemdesign-parent.git
git submodule foreach -q --recursive 'branch="$( git symbolic-ref refs/remotes/origin/HEAD --short | grep -oE "[^/]+$")"; git checkout $branch'
Upvotes: 1
Reputation: 1799
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.
Upvotes: 2