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

From: D. Ben Knoble <hidden>
Date: 2026-01-20 02:20:47

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help