git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rename default branch from 'master' to 'main' in refs and test scripts
@ 2025-08-26  4:52 Wing Huang via GitGitGadget
  2025-08-26  9:14 ` Andreas Schwab
  2025-08-26  9:58 ` Phillip Wood
  0 siblings, 2 replies; 6+ messages in thread
From: Wing Huang via GitGitGadget @ 2025-08-26  4:52 UTC (permalink / raw)
  To: git; +Cc: Wing Huang, Wing Huang

From: Wing Huang <huangsen365@gmail.com>

Signed-off-by: Wing Huang <huangsen365@gmail.com>

	modified:   refs.c
	modified:   remote.c
	modified:   t/test-lib.sh
---
    rename default branch from 'master' to 'main' in refs and test scripts
    
    This patch updates Git's default branch name from 'master' to 'main' to
    align with modern naming conventions adopted across the industry.
    
    The change affects only newly initialized repositories and maintains
    full backward compatibility through the existing init.defaultBranch
    configuration option.
    
    Changes made:
    
     * refs.c: Update hardcoded default branch name to 'main'
     * remote.c: Update fallback branch name for remote operations
     * t/test-lib.sh: Update test suite default to 'main'
    
    Compatibility notes:
    
     * Existing repositories are unaffected
     * Users can still set init.defaultBranch=master if preferred
     * The change only applies to new git init operations when no explicit
       branch name is configured
    
    This follows the precedent set when init.defaultBranch configuration was
    introduced in Git 2.28, which already acknowledged the community's move
    toward more inclusive default branch names.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1961%2Fhuangsen365%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1961/huangsen365/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1961

 refs.c        | 2 +-
 remote.c      | 2 +-
 t/test-lib.sh | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 4ff55cf24f6..929e9ce60c6 100644
--- a/refs.c
+++ b/refs.c
@@ -653,7 +653,7 @@ char *repo_default_branch_name(struct repository *r, int quiet)
 		die(_("could not retrieve `%s`"), config_display_key);
 
 	if (!ret) {
-		ret = xstrdup("master");
+		ret = xstrdup("main");
 		if (!quiet)
 			advise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,
 					  _(default_branch_name_advice), ret);
diff --git a/remote.c b/remote.c
index 81d8fc017e1..ffc4089a1c2 100644
--- a/remote.c
+++ b/remote.c
@@ -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);
 	}
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 621cd31ae1d..4e273a6e94d 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -129,7 +129,7 @@ fi
 
 # Explicitly set the default branch name for testing, to avoid the
 # transitory "git init" warning under --verbose.
-: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=main}
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 ################################################################

base-commit: 1fa68948c3d76328236cac73d2adf33c905bd8e3
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts
  2025-08-26  4:52 [PATCH] rename default branch from 'master' to 'main' in refs and test scripts Wing Huang via GitGitGadget
@ 2025-08-26  9:14 ` Andreas Schwab
  2025-08-26  9:58 ` Phillip Wood
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2025-08-26  9:14 UTC (permalink / raw)
  To: Wing Huang via GitGitGadget; +Cc: git, Wing Huang

On Aug 26 2025, Wing Huang via GitGitGadget wrote:

> diff --git a/remote.c b/remote.c
> index 81d8fc017e1..ffc4089a1c2 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -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");

That comment is no longer accurate.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts
  2025-08-26  4:52 [PATCH] rename default branch from 'master' to 'main' in refs and test scripts Wing Huang via GitGitGadget
  2025-08-26  9:14 ` Andreas Schwab
@ 2025-08-26  9:58 ` Phillip Wood
  2025-08-26 11:12   ` Jeff King
  2025-08-26 11:20   ` Phillip Wood
  1 sibling, 2 replies; 6+ messages in thread
From: Phillip Wood @ 2025-08-26  9:58 UTC (permalink / raw)
  To: Wing Huang via GitGitGadget, git; +Cc: Wing Huang, Andreas Schwab

On 26/08/2025 05:52, Wing Huang via GitGitGadget wrote:
> From: Wing Huang <huangsen365@gmail.com>
> 
> Signed-off-by: Wing Huang <huangsen365@gmail.com>
> 
> 	modified:   refs.c
> 	modified:   remote.c
> 	modified:   t/test-lib.sh
> ---
>      rename default branch from 'master' to 'main' in refs and test scripts
>      
>      This patch updates Git's default branch name from 'master' to 'main' to
>      align with modern naming conventions adopted across the industry.

Thank you for your interest in this. We're currently planning to change 
the default branch name when Git 3.0 is released as documented in 
Documentation/BreakingChanges.adoc. I've actually been working on some 
patches to do that at [1] which are almost ready to submit.

>       * refs.c: Update hardcoded default branch name to 'main'

Once we've done that we can also remove the advice about setting a 
default branch name.

>       * 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.

>       * t/test-lib.sh: Update test suite default to 'main'

GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is intended to aid the transition 
from master to main, once the branch name is changed it can be removed 
(with a little bit of work).

Thanks

Phillip

[1] 
https://github.com/git/git/compare/master...phillipwood:git:initial-branch-is-main

>      Compatibility notes:
>      
>       * Existing repositories are unaffected
>       * Users can still set init.defaultBranch=master if preferred
>       * The change only applies to new git init operations when no explicit
>         branch name is configured
>      
>      This follows the precedent set when init.defaultBranch configuration was
>      introduced in Git 2.28, which already acknowledged the community's move
>      toward more inclusive default branch names.
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1961%2Fhuangsen365%2Fmaster-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1961/huangsen365/master-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1961
> 
>   refs.c        | 2 +-
>   remote.c      | 2 +-
>   t/test-lib.sh | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/refs.c b/refs.c
> index 4ff55cf24f6..929e9ce60c6 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -653,7 +653,7 @@ char *repo_default_branch_name(struct repository *r, int quiet)
>   		die(_("could not retrieve `%s`"), config_display_key);
>   
>   	if (!ret) {
> -		ret = xstrdup("master");
> +		ret = xstrdup("main");
>   		if (!quiet)
>   			advise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,
>   					  _(default_branch_name_advice), ret);
> diff --git a/remote.c b/remote.c
> index 81d8fc017e1..ffc4089a1c2 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -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);
>   	}
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 621cd31ae1d..4e273a6e94d 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -129,7 +129,7 @@ fi
>   
>   # Explicitly set the default branch name for testing, to avoid the
>   # transitory "git init" warning under --verbose.
> -: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
> +: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=main}
>   export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
>   
>   ################################################################
> 
> base-commit: 1fa68948c3d76328236cac73d2adf33c905bd8e3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts
  2025-08-26  9:58 ` Phillip Wood
@ 2025-08-26 11:12   ` Jeff King
  2025-08-27 13:26     ` Phillip Wood
  2025-08-26 11:20   ` Phillip Wood
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2025-08-26 11:12 UTC (permalink / raw)
  To: phillip.wood; +Cc: Wing Huang via GitGitGadget, git, Wing Huang, Andreas Schwab

On Tue, Aug 26, 2025 at 10:58:55AM +0100, Phillip Wood wrote:

> >       * 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:

> > @@ -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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts
  2025-08-26  9:58 ` Phillip Wood
  2025-08-26 11:12   ` Jeff King
@ 2025-08-26 11:20   ` Phillip Wood
  1 sibling, 0 replies; 6+ messages in thread
From: Phillip Wood @ 2025-08-26 11:20 UTC (permalink / raw)
  To: Wing Huang via GitGitGadget, git; +Cc: Wing Huang, Andreas Schwab

On 26/08/2025 10:58, Phillip Wood wrote:
> On 26/08/2025 05:52, Wing Huang via GitGitGadget wrote:
>> From: Wing Huang <huangsen365@gmail.com>
>>
>>      rename default branch from 'master' to 'main' in refs and test 
>> scripts
>>      This patch updates Git's default branch name from 'master' to 
>> 'main' to
>>      align with modern naming conventions adopted across the industry.
> 
> Thank you for your interest in this. We're currently planning to change 
> the default branch name when Git 3.0 is released as documented in 
> Documentation/BreakingChanges.adoc. 

Oh, sorry it seems I imagined that. I've just checked and there is no 
entry in that document about the default branch name. I do think that 
the 3.0 release would be a good time to change the default branch name 
though.

Thanks

Phillip


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts
  2025-08-26 11:12   ` Jeff King
@ 2025-08-27 13:26     ` Phillip Wood
  0 siblings, 0 replies; 6+ messages in thread
From: Phillip Wood @ 2025-08-27 13:26 UTC (permalink / raw)
  To: Jeff King, phillip.wood
  Cc: Wing Huang via GitGitGadget, git, Wing Huang, Andreas Schwab

Hi Peff

On 26/08/2025 12:12, Jeff King wrote:
> On Tue, Aug 26, 2025 at 10:58:55AM +0100, Phillip Wood wrote:
> 
>>>        * 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:

Thanks for clarifying that

Phillip

>>> @@ -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.

I just tried cloning a repository with an unborn head and the clone >
> -Peff
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-27 13:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26  4:52 [PATCH] rename default branch from 'master' to 'main' in refs and test scripts Wing Huang via GitGitGadget
2025-08-26  9:14 ` Andreas Schwab
2025-08-26  9:58 ` Phillip Wood
2025-08-26 11:12   ` Jeff King
2025-08-27 13:26     ` Phillip Wood
2025-08-26 11:20   ` Phillip Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).