3

Let's assume that we've got some git submodule in directory "submod". Now I'm doing such commands:

# git submodule update --init submod
# cd submod
# git branch
* (no branch)
master

If submodule located in directory "submod" has many branches - how do I find which of them should I checkout? I know that git remember only git hash of submodule and not branch name - so how to find branch name?

user2699113
  • 4,262
  • 3
  • 25
  • 43

2 Answers2

3

The branch name is not stored in the parent repository. It only stores the hash of the commit. This is because branch names are not reliable, and can change or even disappear over time. Submodules only ever update to the correct hash, and thus always update into a 'detached head' state.

Gary Fixler
  • 5,632
  • 2
  • 23
  • 39
2

how do I find which of them should I checkout?

You should be able to list them with git branch -avvv.

You can then list all the branches which include the commit currently checked out with

git branch -avvv --contain HEAD

You can pick one.

Then you can register the branch you have chosen in order for the submodule to update its HEAD with the latest commit fetched from said branch: see "Git submodules: Specify a branch/tag".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250