3

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?

user989988
  • 3,006
  • 7
  • 44
  • 91
  • Hi, Just checking in to see whether this issue is still blocking you now? Any update for this issue? – Vito Liu Dec 10 '20 at 09:42

1 Answers1

7

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.

Leonardo Dagnino
  • 2,914
  • 7
  • 28