0

I have a project with a master and staging branch. The project has a submodule which also had a master and staging branch.

My .gitmodules file has referenced the branch correctly so e.g. my project on branch master has the following

[submodule "src/mysubmodule"]
    path = src/mysubmodule
    url = https://username@bitbucket.org/username/mysubmodule.git
    branch = master

and the branch staging has

[submodule "src/mysubmodule"]
    path = src/mysubmodule
    url = https://username@bitbucket.org/username/mysubmodule.git
    branch = staging

I want to switch the branch of my submodule(s) as well if i switch the branch of my project. git checkout master etc.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
dknaack
  • 60,192
  • 27
  • 155
  • 202
  • `git submodule update`? – hjpotter92 Sep 08 '16 at 18:12
  • No, does not switch the submodules branch – dknaack Sep 08 '16 at 18:17
  • `git submodule update` has additional [flags available](https://devdocs.io/git/git-submodule). "The "updating" can be done in several ways depending on command line options and the value of `submodule..update` configuration variable." I might be wrong, but I think checkout is what you're looking for here. – hjpotter92 Sep 08 '16 at 18:19

1 Answers1

0

The submodule.<id>.branch configuration is just a hint for git submodule update --remote or ... --rebase. It will be ignored by the default --checkout operation.

You have to update the submodules of the "staging" branch manually (e.g. by git submodle update --remote) and commit these changes then.

ensc
  • 6,704
  • 14
  • 22