Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change git submodule tracking remote branch?

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?

like image 842
Rohit Avatar asked Oct 19 '22 03:10

Rohit


1 Answers

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

like image 54
Dmitriy Matveev Avatar answered Oct 22 '22 02:10

Dmitriy Matveev