git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git submodule update remote keeps using previous default branch

From
SLSjoerd Langkemper <sjoerd-2021@linuxonly.nl>
Date
Oct 15, 2021, 10:45 UTC
Message-ID
<CAA1vfcYSZWEXsDBD2_0o48EYbU9e9nKVoFdQ0M=fDAOMki3bng@mail.gmail.com>
In-Reply-To
<CAA1vfca+kPSsitsZad-bmrd+o1ay60NXZrH2zGLpwN69Px-rtw@mail.gmail.com>

The submodule is updated according to where `origin/HEAD` points. The `origin/HEAD` ref of a repository is not automatically updated when the upstream default branch changes. However, this can be forced with `git remote set-head origin -a`.

I think it is a little bit surprising that `origin/HEAD` does not necessarily point to the remote default branch. However, changing the default branch should be pretty rare, so I understand this is not checked every time.

Regards,
Sjoerd Langkemper

On Fri, Oct 15, 2021 at 10:34 AM Sjoerd Langkemper <sjoerd-2021@linuxonly.nl> wrote:

Show 32 quoted lines
>
> I am having trouble with git 2.33.1 checking out the wrong branch for
> submodules for which the default branch has changed. `git submodule
> update --remote` seems to remember the branch name to retrieve, while
> I expect it to use the remote HEAD every time. This causes unexpected
> behaviour when the remote HEAD starts pointing to another branch.
>
> I create a new git project and add a submodule, with `git submodule
> add git@host:foo/testproject.git`.
>
> This checks out the default branch, `master` in this case. `git remote
> show origin` also shows that `master` is the HEAD branch. Running `git
> submodule update --remote` updates the submodule to the latest master.
>
> Now I change the default branch on the remote (using Gitlab's web
> interface) to `newmaster`.
>
> `git remote show origin` now correctly shows `newmaster` as the
> remote's HEAD branch. However, running `git submodule update --remote`
> still updates the submodule to the latest `master` branch, while I
> expect it to update to the lastest `newmaster` branch.
>
> There's no branch specified in .gitmodules or .git/config. I am not
> sure how git remembers the branch. When switching `testproject` to
> `newmaster` manually and then running `git submodule update --remote`,
> it is reset to `master` again.
>
> Is this a bug? Can I change the branch somehow?
>
> Regards,
>
> Sjoerd Langkemper
Previous: Bryan Turner
Message 3 of 3 in “Git submodule update remote keeps using previous default branch”
  1. Sjoerd LangkemperOct 15, 2021
  2. Bryan TurnerOct 15, 2021
  3. Sjoerd LangkemperOct 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.