2

Since a while (v1.8.2), git submodule allow us to track a specific branch:

git submodule add -b <tracked_branch> <added_sobmodule>

That's pretty useful in a use case where you use meta-projet to track a bunch of project in their releasing branch from a public remote.

Now, I have a use case in which I need to track both a release branch and a dev branch. So I add to the previous command:

git submodule add -b <another_tracked_branch> <already_added_sobmodule>

I get this error (v2.12.0):

'already_added_sobmodule' existe déjà dans l'index

Which mean that already_added_sobmodule already exist in the index...

How could I track (using submodule) only 2 of the branches of a public git remote?

jvtrudel
  • 1,235
  • 3
  • 15
  • 28

2 Answers2

4

You could use 2 branches in your parent repo.

In the second branch, you would change the branch of the submodule in your .gitmodules file.

And since Git 2.5, you can checkout the same Git repo in separate folders (one per branches, with the git worktree command)

But the point remains: one submodule cannot track two branches at the same time.

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

You have to specify the name and path.

git submodule add -b <branch A> --name <name A> <url> <path A>
git submodule add -b <branch B> --name <name B> <url> <path B>

lukee
  • 843
  • 9
  • 12
  • 1
    Thanks for this answer! So long after the question was asked but it was very useful to me and is the only place I've seen it shown that this can actually be done. – Caesar Aug 05 '23 at 22:46