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

git submodule: update --remote --checkout + upstream branch change

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Jan 20, 2026, 02:20 UTC
Message-ID
<CALnO6CCkcp-Pj-M6yCnr3O-DJE3PedEcqGah3e+E9C4Awqf+Kg@mail.gmail.com>

On my build of git.git origin/master (with ps/history merged in, but that shouldn't affect this), I received a confusing error today:

    git submodule update --remote --checkout
    …
    Unable to find refs/remotes/origin/HEAD revision in submodule path
'…submod…'

Turns out the upstream repository had renamed the main branch from master to main, and the git dir (.git/modules/…submod…/refs/remotes/origin) still had

    ref: refs/remotes/origin/main

This is weird, because I could successfully "git fetch" inside the submodule, and "git ls-remote" showed HEAD on the remote pointing at the same place as refs/heads/main. In fact, I was so puzzled that I didn't understand where this error had come from (grepping in the source found builtin/submodule--helper.c; GIT_TRACE2=1 was not really any help here), nor did I have very high hopes of solving it except that I happened to know where to look for occurrences of "master" that might need changed.

A simple "git -C …submod… remote set-head origin -a" solves the problem; is there something the submodule code needs to do to handle this more gracefully, such as fixing it automatically or letting the user know what possible causes are? Or something I can do to avoid this coming up with other repositories I use as submodules?

-- 
D. Ben Knoble
Message 1 of 1 in “git submodule: update --remote --checkout + upstream branch change”
  1. D. Ben KnobleJan 20, 2026

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.