0

Is it possible to have different submodules within different branches? For example, branch 1 would only see submodule 1 and branch 2 would only see submodule 2.

One option is to use git submodule deinit before moving to another branch, and then running git submodule init and git submodule update after returning to the first branch. This works, but adds a number of additional steps every time a new branch is to be checked out.

A similar question was asked here, but this was 10 years ago and I'm wondering if there is a more up-to-date way of doing this.

intervort
  • 95
  • 4
  • 1
    1st thing to try is [`git checkout --recurse-submodules`](https://stackoverflow.com/a/55631474/7976758). Please read also https://stackoverflow.com/a/61551146/7976758 – phd Apr 04 '23 at 18:47
  • 2nd thing to try is `post-checkout` and `post-merge` hooks — you don't need to do submodules cleanup/setup manually. Two examples of such hooks: [small](https://stackoverflow.com/a/37383406/7976758) and [bigger](https://github.com/chaitanyagupta/gitutils/blob/973696c7e556d6a67ef890e159dbd0290233a820/submodule-hooks/post-merge-checkout). – phd Apr 04 '23 at 18:56

1 Answers1

0

As mentioned by @phd, the --recurse-submodules is the way to go

intervort
  • 95
  • 4
  • Deleting a submodule work tree is so fraught I doubt automating it will ever be built in, there's just too much potential for deleting things that shouldn't be deleted. – jthill Apr 04 '23 at 21:26