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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 13, 2021, 20:37 UTC
Message-ID
<xmqqlf9lly3d.fsf@gitster.g>
In-Reply-To
<CAHwnEogvmTZ-VS5GksoGEiyo3EHO+At+xeWa3frXUESD3HicnQ@mail.gmail.com>
Sam Bostock <sam.bostock@shopify.com> writes:
Show 6 quoted lines
> 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.
That is working as intended.

Since its inception, refs/remotes/origin/HEAD has been designed to mean "the branch, which the owner of the repository considers the most interesting for his/her purpose to keep track in the 'origin' remote repository". It is perfectly OK to repoint origin/HEAD to point at another branch you are interested in after you make a clone.

The origin/HEAD happens to be primed by noticing what the remote repository sets HEAD to point to their branch upon cloning, but that is purely for convenience (i.e. HEAD branch of a repository offered for cloning points at a branch the owner of the repository being cloned considers the primary branch in his/her repository, and that often coincides with the earlier definition of origin/HEAD for those who clone such a repository). It would be a bug to update it to something other than you set (either passively by keeping what "clone" gave you initially, or actively by updating it to point at another branch) upon "git fetch" from the remote.

There was an idea floated to use the same mechanism used by "git clone" to prime origin/HEAD upon "git fetch" when origin/HEAD is missing, and I do not think there were many objections against the idea, so that may happen sometime in the future. It may also be possible to add "git fetch --reset-remote-tracking-HEAD" option to make "fetch" overwrite existing origin/HEAD but somebody has to propose such a change, argue for its benefit and get it accepted by the community.

Thanks.
Previous: Sam BostockNext: Andreas Schwab
Message 2 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.