0

I have a parent repository named 'A' that contain a submodule 'B' When I clone 'A' i got 'B' detached HEAD to a specific commit.

My clone command is:

git clone --recurse-submodules https://github.com/.../A.git

After that i am enter to 'A' folder:

cd A

I am automatically on 'develop' branch - Great!

When I am enter to my submodule folder:

cd B

I am automatically got (HEAD detached at 6dce2e1) - WHY ?!?! I want to be automatically on develop also here.

I have read all previous question - nothing help!

What i have tried:

  1. delete submodule -> commit -> add again with write implicit develop branch name.

  2. checkout B repo to develop and commit it in A repo

I have already tried this post: Why is my GIT Submodule HEAD detached from master?

Also, tries this: How can I specify a branch/tag when adding a Git submodule?

It is just do not solve my issue! When i am cloning to new folder the issue is come back!

But it is simply not solved my issue.

How can i solve it? and why it is suddenly happened?

Matan Marciano
  • 333
  • 4
  • 13
  • No, I have already tries this answer and this is not solved my issue – Matan Marciano May 29 '19 at 09:49
  • The submodule is *supposed* to be detached. That's not an error, that's the way submodules are intended to be used. I added another old question whose accepted answer is, I think, better. – torek May 29 '19 at 16:36
  • Thank you for your answer but this issue was not shown before. it is suddenly happened. I want to clone my 'A' and 'B' with develop branch automatically. not detached head. – Matan Marciano May 30 '19 at 07:32
  • You can't: cloning a new repository with recursive submodule cloning *always* puts the submodules in detached HEAD mode. (If you have a counterexample, include details—a [mcve]—in your question.) – torek May 30 '19 at 07:34
  • @torek Tnx again, but it is possible for sure. if you will create two new repo's and declare the submodule from scratch everything will be ok – Matan Marciano May 30 '19 at 08:18
  • If you are talking about `mkdir testrepo; git init; mkdir submodule; cd submodule; git init; echo test a submodule > README; git add README; git commit -m 'create submodule commit'; cd ..; git submodule add ./submodule`: then at that point, the submodule named `submodule` *is* on a branch, but that's because you *didn't* clone it. – torek May 30 '19 at 10:09
  • I talked about all what you write and remove dir and clone again – Matan Marciano May 30 '19 at 10:35
  • Remove what dir? Clone from where? (Note that neither repository I just created was ever pushed anywhere—if you remove them, there is nothing to clone!) Again, a [mcve] is important. Without it, there's no way for me to know whether I'm doing what you're doing. – torek May 30 '19 at 10:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194170/discussion-between-matan-marciano-and-torek). – Matan Marciano May 30 '19 at 11:08

0 Answers0