0

I have checked out a project that includes some submodules.

First I checked out my project and then the submodules:

git clone git@my-gitlab-server:namespace/project.git

Initiatiated the submodules for that branch with the latest:

git submodule update --init --recursive

Then I checked out the specific branch that includes the submodules. I just want to get the branch name of each sumbodule.

But:

$ git --git-dir path/to/my/submodule rev-parse --abbrev-ref HEAD
fatal: not a git repository: 'path/to/my/submodule'


$ cd  path/to/my/submodule 
$ (detached*)$ git branch
* (HEAD detached at 24bbc55)
  develop

Why the first command shows that it is not a git submodule? (while it is) The checkout is done from a specific branch ('develop') of the submodule. How can I get the actual branch name (and not the git sha?)

pkaramol
  • 16,451
  • 43
  • 149
  • 324

1 Answers1

0

From your project list the branch name and status of each submodule in your git repository:

git submodule foreach 'git status'

From your submodule list the branch name of that submodule

git branch

The reason for the detached state of git submodules can be found in another question that has been made here: stackoverflow.com/a/48556186/3564632

denis_lor
  • 6,212
  • 4
  • 31
  • 55