3

I have repo, which contain lots of submodules. Every submodule was initialized with -b branch_rev_1. I want to switch state of this repo, changing every submodule's branch with -b branch_rev_2 (so I will be able to build app with different revision of dependencies).

But making checkout -b branch_rev_2 inside submodule's directory does not change record in .gitmodules file. Is there any way for switch state of all submodules after changing branch name in .gitmodules file (or vice versa, sync .gitmodules description and other configuration in .git folder after checking out specific revision inside submodule) ?

Vladimir
  • 33
  • 2
  • 5

1 Answers1

1

You can edit .gitmodules manually (using an editor) or using git config -f .gitmodules submodule.<name>.branch <branch_name>. After modifying sync it to .git/config with the command git submodule sync and update submodules using git submodule update --init --remote.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Using `git config -f .gitmodules` didn't work for me, the .gitmodules file did not update. I had to use the solution from this answer: https://stackoverflow.com/a/73474931/5488464 – fishlein Mar 07 '23 at 15:04
  • @fishlein What was exact command? `git config -f .gitmodules` is not enough, it must be something like `git config -f .gitmodules submodule..branch ` – phd Mar 07 '23 at 15:07
  • Thanks, that is clearer. I was under the impression that the command would take the branch that the submodule is currently checked out to (`branch_rev_2` in the OP's question), but actually you are suggesting to manually overwrite the file, which will ignore whatever has been checked out in the submodule. It think you should make that clear in your answer. – fishlein Mar 08 '23 at 10:18
  • @fishlein Tnx, I updated the answer a bit. "*…take the branch that the submodule is currently checked out to…*" That could be scripted — get the checked out branch, set it in `.gitmodules`. The answer you linked above (`git submodule set-branch -b v1.0.0 xyz`) does the same — set the branch to a fixed name, not to the checked out branch name. – phd Mar 08 '23 at 10:57