首页 > 解决方案 > Can Git submodules track same name branch always based on superproject branch name

问题描述

I'm migrating java maven project code to GIT from Perforce (P4) and where every component is released individually and parallel releases supported since git does not allow to checkout by subdir unlike p4 I decided to use Git Submodules.

Now My Superproject has multiple submodules and each submodule has a master, develop and support branch so that my super project's M(master) is tracking M of submodules, D tracking D of submodules and S tracking S of submodules.

superproject 
    -- pom.xml
    submodule 1
         -- pom.xml
    submodule 2
         -- pom.xml
    .
    .
    submodule 10 
         -- pom.xml

So I want super project branch should track the same branch from all submodules

 Superproject (Master, Dev, Support)
  - submodule 1  (Master, Dev, Support)
  - submodule 2  (Master, Dev, Support)
  - ....
  - submodule 3 (Master, Dev, Support)

is there an easy way to enforce that whatever branch the superporject is checked out the submodules should be checked out to the same branch as well ?

I tried the adding branchs in .gitmodule file and it works but it needs to be updated after every release before merging it to master from dev branch ( Git Flow).

I'm using this but its becoming manual and confusing to new users.

 git submodule foreach --recursive git checkout develop

is there any better way to automate these things ?

标签: gitmavenperforcegit-submodules

解决方案


推荐阅读