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

Re: Find main branch

From
Jeff King <peff@peff.net>
Date
Jan 14, 2016, 21:04 UTC
Message-ID
<20160114210452.GA10825@sigill.intra.peff.net>
In-Reply-To
<CAPMsMoBNzmK618NPP-VXP_70hTxTsa13O9f_usiCPJ-SUOUz_g@mail.gmail.com>
On Thu, Jan 14, 2016 at 06:40:15PM +0000, pedro rijo wrote:
Show 6 quoted lines
> Stefan Beller solution is based on the server, which may not be very
> easy to do when dealing with Github/Bitbucket/Gitlab and other God
> knows which provider.
> 
> Konstantin ls-remote solution is the one I'm already using, but if I
> have several branches on that commit, I will not be able to decide.

Right. Git used to guess, but that was not great exactly because of the ambiguity you have seen. Servers started publishing the value of the HEAD symref in git v1.8.4.3. I'd expect that to be available on any modern server.

There's unfortunately not a plumbing command to directly access the value, but "git remote set-head $remote -a" will query the remote and update refs/remotes/$remote/HEAD appropriately. As a bonus, if it's an older server that doesn't provide the HEAD value, it will fallback to the "old" heuristics (see guess_remote_head for details).

-Peff
Previous: Jeff King
Message 11 of 11 in “Find main branch”
  1. pedro rijoJan 14, 2016
  2. Stefan BellerJan 14, 2016
  3. Konstantin KhomoutovJan 14, 2016
  4. pedro rijoJan 14, 2016
  5. Konstantin KhomoutovJan 14, 2016
  6. Bryan TurnerJan 14, 2016
  7. Jeff KingJan 14, 2016
  8. pedro rijoJan 15, 2016
  9. Junio C HamanoJan 15, 2016
  10. Jeff KingJan 15, 2016
  11. Jeff KingJan 14, 2016

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.