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

Re: Syncing HEAD

From
Jeff King <peff@peff.net>
Date
Aug 14, 2018, 21:06 UTC
Message-ID
<20180814210616.GA32367@sigill.intra.peff.net>
In-Reply-To
<CAP8UFD0_jpKdcDvNx5CYnmyDMagE_O-E7cef5VthaT_w-=4xsA@mail.gmail.com>
On Tue, Aug 14, 2018 at 10:09:37PM +0200, Christian Couder wrote:
Show 10 quoted lines
> When cloning with --mirror, the clone gets its HEAD initialized with
> the value HEAD has in its origin remote. After that if HEAD changes in
> origin there is no simple way to sync HEAD at the same time as the
> refs are synced.
> 
> It looks like the simplest way to sync HEAD is:
> 
> 1) git remote show origin
> 2) parse "HEAD branch: XXX" from the output of the above command
> 3) git symbolic-ref HEAD refs/heads/XXX
How about:
  git remote set-head origin -a
?
> It looks like it would be quite easy to add an option to `fetch` to
> sync HEAD at the same time as regular refs are synced because every
> fetch from an origin that uses a recent Git contains something like:

I think the "remote set-head" option is not very discoverable, since people are used to working with "fetch", making it the natural place to look. Just like we ported "remote update" over to "fetch --all", I think it would be sensible to have "fetch --update-head" or similar.

One tricky thing is that the name "refs/remotes/<remote>/HEAD" is only special by convention, and that convention is known on the writing side only by git-clone and git-remote. So obviously:

  git fetch --update-head https://example.com/
is nonsense. We don't even have a ref. What should:
  git config remote.origin.fetch refs/heads/*:refs/remotes/foo/*
  git fetch --update-head origin

do? Should it update based no the remote name, or based on the refspec? What happens if there are several refspecs? Etc.

99% of the time those questions won't come up. But we should design so that we do the obvious thing in those 99%, and something sane in the other 1%.

-Peff
Previous: Brandon WilliamsNext: Jeff King
Message 4 of 10 in “Syncing HEAD”
  1. Christian CouderAug 14, 2018
  2. Stefan BellerAug 14, 2018
  3. Brandon WilliamsAug 14, 2018
  4. Jeff KingAug 14, 2018
  5. Jeff KingAug 14, 2018
  6. Christian CouderAug 15, 2018
  7. Jeff KingAug 17, 2018
  8. Junio C HamanoAug 17, 2018
  9. Jeff KingAug 17, 2018
  10. Ævar Arnfjörð BjarmasonAug 14, 2018

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.