Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submodule - update .gitmodules for specifying a branch name

I have added a submodule to an ADO repository:

.gitmodules

[submodule "public"]
    path = public
    url = https://xyz.visualstudio.com/DefaultCollection/abc/_git/STW-Sol-public

Is there a git command to update .gitmodules for specifying a branch name?

like image 417
user989988 Avatar asked Oct 16 '25 17:10

user989988


1 Answers

Since git 2.22, you can use git submodule set-branch for that:

git submodule set-branch --branch mybranch public

This adds a branch = mybranch to your .gitmodules. Which you may also add manually, if you'd rather do so.

More information can be found on git-submodule(1).

You may also want to take a look at this answer, which elaborates more on what exactly it means to track a branch. Most importantly:

git submodule add -b is not some magically way to keep everything up to date with a branch. It is simply adds information about a branch in the .gitmodules file and gives you the option to update the submodule object to the latest commit of a specified branch before populating it.

like image 200
Leonardo Dagnino Avatar answered Oct 18 '25 11:10

Leonardo Dagnino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!