{"thread":{"id":"64033","subject":"[PATCH] rename default branch from 'master' to 'main' in refs and test scripts","startedAt":"2025-08-26T04:52:05Z","lastAt":"2025-08-27T13:26:48Z","messageCount":6,"participants":["Wing Huang via GitGitGadget","Andreas Schwab","Phillip Wood","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"524918","messageId":"pull.1961.git.1756183921623.gitgitgadget@gmail.com","threadId":"64033","inReplyTo":null,"subject":"[PATCH] rename default branch from 'master' to 'main' in refs and test scripts","fromName":"Wing Huang via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-08-26T04:52:01Z","receivedAt":"2025-08-26T04:52:05Z","isPatch":true,"sender":{"key":"name:Wing Huang","avatar":null},"body":"From: Wing Huang <huangsen365@gmail.com>\n\nSigned-off-by: Wing Huang <huangsen365@gmail.com>\n\n\tmodified:   refs.c\n\tmodified:   remote.c\n\tmodified:   t/test-lib.sh\n---\n    rename default branch from 'master' to 'main' in refs and test scripts\n    \n    This patch updates Git's default branch name from 'master' to 'main' to\n    align with modern naming conventions adopted across the industry.\n    \n    The change affects only newly initialized repositories and maintains\n    full backward compatibility through the existing init.defaultBranch\n    configuration option.\n    \n    Changes made:\n    \n     * refs.c: Update hardcoded default branch name to 'main'\n     * remote.c: Update fallback branch name for remote operations\n     * t/test-lib.sh: Update test suite default to 'main'\n    \n    Compatibility notes:\n    \n     * Existing repositories are unaffected\n     * Users can still set init.defaultBranch=master if preferred\n     * The change only applies to new git init operations when no explicit\n       branch name is configured\n    \n    This follows the precedent set when init.defaultBranch configuration was\n    introduced in Git 2.28, which already acknowledged the community's move\n    toward more inclusive default branch names.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1961%2Fhuangsen365%2Fmaster-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1961/huangsen365/master-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1961\n\n refs.c        | 2 +-\n remote.c      | 2 +-\n t/test-lib.sh | 2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 4ff55cf24f6..929e9ce60c6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -653,7 +653,7 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n \tif (!ret) {\n-\t\tret = xstrdup(\"master\");\n+\t\tret = xstrdup(\"main\");\n \t\tif (!quiet)\n \t\t\tadvise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,\n \t\t\t\t\t  _(default_branch_name_advice), ret);\ndiff --git a/remote.c b/remote.c\nindex 81d8fc017e1..ffc4089a1c2 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2379,7 +2379,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \t\t\treturn copy_ref(r);\n \n \t\t/* Fall back to the hard-coded historical default */\n-\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n+\t\tr = find_ref_by_name(refs, \"refs/heads/main\");\n \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\n \t}\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 621cd31ae1d..4e273a6e94d 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -129,7 +129,7 @@ fi\n \n # Explicitly set the default branch name for testing, to avoid the\n # transitory \"git init\" warning under --verbose.\n-: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}\n+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=main}\n export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n ################################################################\n\nbase-commit: 1fa68948c3d76328236cac73d2adf33c905bd8e3\n-- \ngitgitgadget\n"},{"id":"524933","messageId":"875xeamolx.fsf@igel.home","threadId":"64033","inReplyTo":"pull.1961.git.1756183921623.gitgitgadget@gmail.com","subject":"Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2025-08-26T09:14:18Z","receivedAt":"2025-08-26T09:23:03Z","isPatch":true,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Aug 26 2025, Wing Huang via GitGitGadget wrote:\n\n> diff --git a/remote.c b/remote.c\n> index 81d8fc017e1..ffc4089a1c2 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -2379,7 +2379,7 @@ struct ref *guess_remote_head(const struct ref *head,\n>  \t\t\treturn copy_ref(r);\n>  \n>  \t\t/* Fall back to the hard-coded historical default */\n> -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n> +\t\tr = find_ref_by_name(refs, \"refs/heads/main\");\n\nThat comment is no longer accurate.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"524934","messageId":"0a574b62-273e-4519-855f-66c554cd93c7@gmail.com","threadId":"64033","inReplyTo":"pull.1961.git.1756183921623.gitgitgadget@gmail.com","subject":"Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-08-26T09:58:55Z","receivedAt":"2025-08-26T09:58:58Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 26/08/2025 05:52, Wing Huang via GitGitGadget wrote:\n> From: Wing Huang <huangsen365@gmail.com>\n> \n> Signed-off-by: Wing Huang <huangsen365@gmail.com>\n> \n> \tmodified:   refs.c\n> \tmodified:   remote.c\n> \tmodified:   t/test-lib.sh\n> ---\n>      rename default branch from 'master' to 'main' in refs and test scripts\n>      \n>      This patch updates Git's default branch name from 'master' to 'main' to\n>      align with modern naming conventions adopted across the industry.\n\nThank you for your interest in this. We're currently planning to change \nthe default branch name when Git 3.0 is released as documented in \nDocumentation/BreakingChanges.adoc. I've actually been working on some \npatches to do that at [1] which are almost ready to submit.\n\n>       * refs.c: Update hardcoded default branch name to 'main'\n\nOnce we've done that we can also remove the advice about setting a \ndefault branch name.\n\n>       * remote.c: Update fallback branch name for remote operations\n\nI think we want to keep the fallback to \"master\" but check for \"main\" \nfirst. Otherwise we'll stop finding the default branch where the remote \nis still using master.\n\n>       * t/test-lib.sh: Update test suite default to 'main'\n\nGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is intended to aid the transition \nfrom master to main, once the branch name is changed it can be removed \n(with a little bit of work).\n\nThanks\n\nPhillip\n\n[1] \nhttps://github.com/git/git/compare/master...phillipwood:git:initial-branch-is-main\n\n>      Compatibility notes:\n>      \n>       * Existing repositories are unaffected\n>       * Users can still set init.defaultBranch=master if preferred\n>       * The change only applies to new git init operations when no explicit\n>         branch name is configured\n>      \n>      This follows the precedent set when init.defaultBranch configuration was\n>      introduced in Git 2.28, which already acknowledged the community's move\n>      toward more inclusive default branch names.\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1961%2Fhuangsen365%2Fmaster-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1961/huangsen365/master-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1961\n> \n>   refs.c        | 2 +-\n>   remote.c      | 2 +-\n>   t/test-lib.sh | 2 +-\n>   3 files changed, 3 insertions(+), 3 deletions(-)\n> \n> diff --git a/refs.c b/refs.c\n> index 4ff55cf24f6..929e9ce60c6 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -653,7 +653,7 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n>   \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n>   \n>   \tif (!ret) {\n> -\t\tret = xstrdup(\"master\");\n> +\t\tret = xstrdup(\"main\");\n>   \t\tif (!quiet)\n>   \t\t\tadvise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,\n>   \t\t\t\t\t  _(default_branch_name_advice), ret);\n> diff --git a/remote.c b/remote.c\n> index 81d8fc017e1..ffc4089a1c2 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -2379,7 +2379,7 @@ struct ref *guess_remote_head(const struct ref *head,\n>   \t\t\treturn copy_ref(r);\n>   \n>   \t\t/* Fall back to the hard-coded historical default */\n> -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n> +\t\tr = find_ref_by_name(refs, \"refs/heads/main\");\n>   \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n>   \t\t\treturn copy_ref(r);\n>   \t}\n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index 621cd31ae1d..4e273a6e94d 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -129,7 +129,7 @@ fi\n>   \n>   # Explicitly set the default branch name for testing, to avoid the\n>   # transitory \"git init\" warning under --verbose.\n> -: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}\n> +: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=main}\n>   export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n>   \n>   ################################################################\n> \n> base-commit: 1fa68948c3d76328236cac73d2adf33c905bd8e3\n\n"},{"id":"524935","messageId":"20250826111234.GA1925107@coredump.intra.peff.net","threadId":"64033","inReplyTo":"0a574b62-273e-4519-855f-66c554cd93c7@gmail.com","subject":"Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-08-26T11:12:34Z","receivedAt":"2025-08-26T11:12:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Aug 26, 2025 at 10:58:55AM +0100, Phillip Wood wrote:\n\n> >       * remote.c: Update fallback branch name for remote operations\n> \n> I think we want to keep the fallback to \"master\" but check for \"main\" first.\n> Otherwise we'll stop finding the default branch where the remote is still\n> using master.\n\nI'm not sure we need to change anything there. Modern Git will generally\nreport the name of the branch pointed to by HEAD back to the client\n(using either a symref capability in protocol v0 or the symref extension\nto the ls-refs list in v2). So the fallback would be needed only for\nvery old servers, in which case \"master\" is probably a better guess.\n\nIIRC, there are cases where v0 does not report the HEAD value when it\npoints to an unborn branch (and while I'd expect most Git servers to\nalways support v2 these days, sometimes the protocol upgrade fails due\nto things like ssh blocking the GIT_PROTOCOL variable). But I don't\nthink that would affect the fallback code:\n\n> > @@ -2379,7 +2379,7 @@ struct ref *guess_remote_head(const struct ref *head,\n> >   \t\t\treturn copy_ref(r);\n> >   \t\t/* Fall back to the hard-coded historical default */\n> > -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n> > +\t\tr = find_ref_by_name(refs, \"refs/heads/main\");\n> >   \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n> >   \t\t\treturn copy_ref(r);\n\nsince it is only about looking for the matching branch name, and not the\nunborn case.\n\nIf we truly have an unborn HEAD on a very old server (with no protocol\nsupport), I think we just end up without checking anything out, which\nmeans HEAD would default to whatever the local client default is.\n\n-Peff\n"},{"id":"524937","messageId":"d471591b-5f95-497e-ac5f-bf186a3c05a1@gmail.com","threadId":"64033","inReplyTo":"0a574b62-273e-4519-855f-66c554cd93c7@gmail.com","subject":"Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-08-26T11:20:48Z","receivedAt":"2025-08-26T11:20:50Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 26/08/2025 10:58, Phillip Wood wrote:\n> On 26/08/2025 05:52, Wing Huang via GitGitGadget wrote:\n>> From: Wing Huang <huangsen365@gmail.com>\n>>\n>>      rename default branch from 'master' to 'main' in refs and test \n>> scripts\n>>      This patch updates Git's default branch name from 'master' to \n>> 'main' to\n>>      align with modern naming conventions adopted across the industry.\n> \n> Thank you for your interest in this. We're currently planning to change \n> the default branch name when Git 3.0 is released as documented in \n> Documentation/BreakingChanges.adoc. \n\nOh, sorry it seems I imagined that. I've just checked and there is no \nentry in that document about the default branch name. I do think that \nthe 3.0 release would be a good time to change the default branch name \nthough.\n\nThanks\n\nPhillip\n\n"},{"id":"525035","messageId":"cf89ccda-442f-4b98-b30d-93f708e64133@gmail.com","threadId":"64033","inReplyTo":"20250826111234.GA1925107@coredump.intra.peff.net","subject":"Re: [PATCH] rename default branch from 'master' to 'main' in refs and test scripts","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-08-27T13:26:44Z","receivedAt":"2025-08-27T13:26:48Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Peff\n\nOn 26/08/2025 12:12, Jeff King wrote:\n> On Tue, Aug 26, 2025 at 10:58:55AM +0100, Phillip Wood wrote:\n> \n>>>        * remote.c: Update fallback branch name for remote operations\n>>\n>> I think we want to keep the fallback to \"master\" but check for \"main\" first.\n>> Otherwise we'll stop finding the default branch where the remote is still\n>> using master.\n> \n> I'm not sure we need to change anything there. Modern Git will generally\n> report the name of the branch pointed to by HEAD back to the client\n> (using either a symref capability in protocol v0 or the symref extension\n> to the ls-refs list in v2). So the fallback would be needed only for\n> very old servers, in which case \"master\" is probably a better guess.\n> \n> IIRC, there are cases where v0 does not report the HEAD value when it\n> points to an unborn branch (and while I'd expect most Git servers to\n> always support v2 these days, sometimes the protocol upgrade fails due\n> to things like ssh blocking the GIT_PROTOCOL variable). But I don't\n> think that would affect the fallback code:\n\nThanks for clarifying that\n\nPhillip\n\n>>> @@ -2379,7 +2379,7 @@ struct ref *guess_remote_head(const struct ref *head,\n>>>    \t\t\treturn copy_ref(r);\n>>>    \t\t/* Fall back to the hard-coded historical default */\n>>> -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n>>> +\t\tr = find_ref_by_name(refs, \"refs/heads/main\");\n>>>    \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n>>>    \t\t\treturn copy_ref(r);\n> \n> since it is only about looking for the matching branch name, and not the\n> unborn case.\n> \n> If we truly have an unborn HEAD on a very old server (with no protocol\n> support), I think we just end up without checking anything out, which\n> means HEAD would default to whatever the local client default is.\n\nI just tried cloning a repository with an unborn head and the clone >\n> -Peff\n> \n\n"}]}