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

`git fetch` not updating 'origin/HEAD' after branch rename

From
Sam Bostock <sam.bostock@shopify.com>
Date
Apr 13, 2021, 20:25 UTC
Message-ID
<CAHwnEogvmTZ-VS5GksoGEiyo3EHO+At+xeWa3frXUESD3HicnQ@mail.gmail.com>
Hi!

Hopefully I followed the instructions on https://git-scm.com/community correctly to report this bug.

Long story short, it seems to me that `git fetch` should update "refs/remotes/origin/HEAD" when the upstream HEAD changes, but it doesn't. See my filled out bug report below.

Thanks,
Sam
----

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
1. Clone a repo with some branch name (say "master") from some remote
origin (say GitHub).
2. Replace/rename the main branch on the remote (say "main").
3. Run `git fetch` locally to sync with remote.
4. Run `git rev-parse --abbrev-ref --verify origin/HEAD`.
What did you expect to happen? (Expected behavior)

The `git fetch` should update the refs accordingly so "origin/HEAD" now points to the new branch, which should be output from the command above:

    $ git rev-parse --abbrev-ref --verify origin/HEAD
    origin/main
What happened instead? (Actual behavior)

The "origin/HEAD" ref seems to not point to anything anymore (because the branch it was pointing to was "deleted"). `git fetch` fails to update it to reflect the change.

    $ git rev-parse --abbrev-ref --verify origin/HEAD
    fatal: Needed a single revision
What's different between what you expected and what actually happened?

The HEAD on origin has changed, but this change is not reflected in the local refs by `git fetch`.

Anything else you want to add:

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.30.2 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /nix/store/74shlfgb18717ixjlpivpxd7iqcyhyn5-bash-4.4-p23/bin/bash uname: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64 compiler info: clang: 7.1.0 (tags/RELEASE_710/final) libc info: no libc information available $SHELL (typically, interactive shell): /usr/local/bin/bash

[Enabled Hooks]
Next: Junio C Hamano
Message 1 of 10 in “`git fetch` not updating 'origin/HEAD' after branch rename”
  1. Sam BostockApr 13, 2021
  2. Junio C HamanoApr 13, 2021
  3. Andreas SchwabApr 13, 2021
  4. Junio C HamanoApr 13, 2021
  5. Chris TorekApr 14, 2021
  6. Jeff KingApr 14, 2021
  7. Ævar Arnfjörð BjarmasonApr 14, 2021
  8. Andreas SchwabApr 14, 2021
  9. Junio C HamanoApr 14, 2021
  10. Jeff KingApr 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.