git submodule: track 2 branches

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?

  • GIT Change Submodule URL in Post-update script
  • How do I manage active development on git submodules
  • How to push a modification on a git submodule without giving username/password
  • Opposite/reverse of git submodule absorbgitdirs?
  • How do I push a public repo with private submodules to Heroku without compromising my password?
  • Git submodule pull overwrite/discard any local changes
  • How to update git submodules in Android Studio?
  • Git repository using directory as externals
  • One Solution collect form web for “git submodule: track 2 branches”

    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.

    Git Baby is a git and github fan, let's start git clone.