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

Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts

From
Jeff King <peff@peff.net>
Date
Aug 26, 2025, 11:12 UTC
Message-ID
<20250826111234.GA1925107@coredump.intra.peff.net>
In-Reply-To
<0a574b62-273e-4519-855f-66c554cd93c7@gmail.com>
On Tue, Aug 26, 2025 at 10:58:55AM +0100, Phillip Wood wrote:
Show 5 quoted lines
> >       * remote.c: Update fallback branch name for remote operations
> 
> I think we want to keep the fallback to "master" but check for "main" first.
> Otherwise we'll stop finding the default branch where the remote is still
> using master.

I'm not sure we need to change anything there. Modern Git will generally report the name of the branch pointed to by HEAD back to the client (using either a symref capability in protocol v0 or the symref extension to the ls-refs list in v2). So the fallback would be needed only for very old servers, in which case "master" is probably a better guess.

IIRC, there are cases where v0 does not report the HEAD value when it points to an unborn branch (and while I'd expect most Git servers to always support v2 these days, sometimes the protocol upgrade fails due to things like ssh blocking the GIT_PROTOCOL variable). But I don't think that would affect the fallback code:

Show 7 quoted lines
> > @@ -2379,7 +2379,7 @@ struct ref *guess_remote_head(const struct ref *head,
> >   			return copy_ref(r);
> >   		/* Fall back to the hard-coded historical default */
> > -		r = find_ref_by_name(refs, "refs/heads/master");
> > +		r = find_ref_by_name(refs, "refs/heads/main");
> >   		if (r && oideq(&r->old_oid, &head->old_oid))
> >   			return copy_ref(r);

since it is only about looking for the matching branch name, and not the unborn case.

If we truly have an unborn HEAD on a very old server (with no protocol support), I think we just end up without checking anything out, which means HEAD would default to whatever the local client default is.

-Peff
Previous: Phillip WoodNext: Phillip Wood
Message 4 of 6 in “rename default branch from 'master' to 'main' in refs and test scripts”
  1. rename default branch from 'master' to 'main' in refs and test scriptsWing Huang via GitGitGadget, Aug 26, 2025
  2. Andreas SchwabAug 26, 2025
  3. Phillip WoodAug 26, 2025
  4. Jeff KingAug 26, 2025
  5. Phillip WoodAug 27, 2025
  6. Phillip WoodAug 26, 2025

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.