I add a submodule using following command
git submodule add -b br1 [repo]
The .gitmodules file has entry branch=br1 . Now I want to switch the branch to br2. I can go into submodule folder and switch the branch but that does not update .gitmodules file.
How I can do that?
Git uses .gitmodules for storing a link to your submodule project, but not a particular version of it. So when you switch branch of the submodule, git .gitmodules file is not changed.
Instead git updates commit number of your submodule version when you change the submodule. If you look at your upper module
git diff
you'll see something like
-Subproject commit 829b869657418fdac7964c3671ed9a378f09c032
+Subproject commit 829b869657418fdac7964c3671ed9a378f09c032-dirty
If you wish everybody uses new submodule branch, you have to commit & push that change (new submodule commit number) into your upper module repo.
Basically it works like a link to the particular submodule version.
Look here for details: https://git-scm.com/book/en/v2/Git-Tools-Submodules#Starting-with-Submodules
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With