0

i have a git repo with multiple submodules.

when checking out, i usually do as follows

git clone URL # without --recursive!

so i have a single main repository, checked out in master

git checkout mybranchname_main_repo

now i have a single main repository checked out in its branch

git submodule update --init # now i checkout submodules because now they point to their supposed branch hash and not the master

now have the main repository in its branch, with its submodules (repos) checkout out to the last commited hash which is typically also in a development branch and not master

the issue im having is that all submodules checkout the last commited hash value and not the branch/head.

is there a command that i can add an additional command making the submodules checkout the branch from their hash value in HEAD?

something like: (warning, this is pseudo code)

git submodule foreach checkout HEAD

phd
  • 82,685
  • 13
  • 120
  • 165
user654789384
  • 305
  • 1
  • 4
  • 21
  • Does this answer your question? [Why is my GIT Submodule HEAD detached from master?](https://stackoverflow.com/questions/18770545/why-is-my-git-submodule-head-detached-from-master) – phd Dec 06 '19 at 12:19
  • https://stackoverflow.com/search?q=%5Bgit-submodules%5D+detached+head – phd Dec 06 '19 at 12:19
  • Does this answer your question? [How can I specify a branch/tag when adding a Git submodule?](https://stackoverflow.com/questions/1777854/how-can-i-specify-a-branch-tag-when-adding-a-git-submodule) – Chris Maes Dec 06 '19 at 12:37

1 Answers1

0

Adding the line branch = <branchname> directly into .gitmodules will allow git submodule update --remote to (effectively) update to the branch. You can also add this information with git submodule add -b.

Alternatively, git submodule foreach exists, and executes an arbitrary shell command in each submodule. Therefore, git submodule foreach 'git checkout HEAD' is also a perfectly valid command to check every submodule out to HEAD.

Alternatively: Check this question which goes into a lot more detail with plenty of options.

Teknikal_Domain
  • 318
  • 1
  • 11