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
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Aug 26, 2025, 09:58 UTC
Message-ID
<0a574b62-273e-4519-855f-66c554cd93c7@gmail.com>
In-Reply-To
<pull.1961.git.1756183921623.gitgitgadget@gmail.com>
On 26/08/2025 05:52, Wing Huang via GitGitGadget wrote:
Show 12 quoted lines
> 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

Show 61 quoted lines
>      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
Previous: Andreas SchwabNext: Jeff King
Message 3 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.