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

[PATCH 6/6] breaking-changes: switch default branch to main

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Aug 27, 2025, 15:24 UTC
Message-ID
<487d1a33130cb2fafadcf98da00a332a7408a0e8.1756308283.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1756308283.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Since 1296cbe4b46 (init: document `init.defaultBranch` better, 2020-12-11) "git-init.adoc" has advertized that the default name of the initial branch may change in the future. The name "main" is chosen to match the default used by the big git forge web sites.

The advice printed when init.defaultBranch is not set is updated to say that the default will change to "main" in Git 3.0. Building with WITH_BREAKING_CHANGES enabled removes the advice, changes the default branch name is "main" and removes support for GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME. The code in guess_remote_head() that looks for "refs/heads/master" is left unchanged as that is only called when the remote server does not support the symref capability in the v0 protocol or the symref extension to the ls-refs list in the v2 protocol. Such an old server is more likely to be using "master" as the default branch name.

With the exception of the "git-init.adoc" the documentation is left unchanged. I had hoped to parameterize the name of the default branch by using an asciidoc attribute. Unfortunately attribute expansion is inhibited by backticks and we use backticks to mark up ref names so that idea does not work. As the changes to git-init.adoc show inserting ifdef's around each instance of the branch name "master" is cumbersome and makes the documentation sources harder to read.

Apart from "git-init.adoc" there are some other files where "master" is used as the name of the initial branch rather than as an example of a branch name such as "user-manual.adoc" and "gitcore-tutorial.adoc". The name appears a lot in those so updating it with ifdef's is not really practical. We can update that document in the 3.0 release cycle. The other documentation where master is used as an example branch name can be gradually converted over time.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 Documentation/BreakingChanges.adoc |  5 +++++
 Documentation/git-init.adoc        | 12 +++++++++---
 advice.c                           |  2 ++
 advice.h                           |  2 ++
 ci/run-build-and-tests.sh          |  1 -
 refs.c                             | 16 +++++++++++++---
 t/t0001-init.sh                    |  9 +++++----
 t/test-lib.sh                      | 15 +++++++++++----
 8 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/Documentation/BreakingChanges.adoc b/Documentation/BreakingChanges.adoc
index f8d2eba061c..93922299321 100644
--- a/Documentation/BreakingChanges.adoc
+++ b/Documentation/BreakingChanges.adoc
@@ -165,6 +165,11 @@ A prerequisite for this change is that the ecosystem is ready to support the
 "reftable" format. Most importantly, alternative implementations of Git like
 JGit, libgit2 and Gitoxide need to support it.
 
+* The default branch name will be `main`. We have been warning that the default
+  name will change since 675704c74dd (init: provide useful advice about
+  init.defaultBranch, 2020-12-11). The new name matches the default branch name
+  used by many of the big git forges.
+
 === Removals
 
 * Support for grafting commits has long been superseded by git-replace(1).
diff --git a/Documentation/git-init.adoc b/Documentation/git-init.adoc
index a0dffba665f..39d4db6bccb 100644
--- a/Documentation/git-init.adoc
+++ b/Documentation/git-init.adoc
@@ -77,9 +77,15 @@ If this is a reinitialization, the repository will be moved to the specified pat
 `-b <branch-name>`::
 `--initial-branch=<branch-name>`::
 Use _<branch-name>_ for the initial branch in the newly created
-repository.  If not specified, fall back to the default name (currently
-`master`, but this is subject to change in the future; the name can be
-customized via the `init.defaultBranch` configuration variable).
+repository.  If not specified, fall back to the default name
+ifndef::with-breaking-changes[]
+(currently `master`, but this will change to `main` when Git 3.0 is released).
+endif::with-breaking-changes[]
+ifdef::with-breaking-changes[]
+(`main`).
+endif::with-breaking-changes[]
+The default name can be customized via the `init.defaultBranch` configuration
+variable.
 
 `--shared[=(false|true|umask|group|all|world|everybody|<perm>)]`::
 
diff --git a/advice.c b/advice.c
index e5f0ff84491..48c49ee4145 100644
--- a/advice.c
+++ b/advice.c
@@ -51,7 +51,9 @@ static struct {
 	[ADVICE_AM_WORK_DIR] 				= { "amWorkDir" },
 	[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] 	= { "checkoutAmbiguousRemoteBranchName" },
 	[ADVICE_COMMIT_BEFORE_MERGE]			= { "commitBeforeMerge" },
+#ifndef WITH_BREAKING_CHANGES
 	[ADVICE_DEFAULT_BRANCH_NAME]			= { "defaultBranchName" },
+#endif /* WITH_BREAKING_CHANGES */
 	[ADVICE_DETACHED_HEAD]				= { "detachedHead" },
 	[ADVICE_DIVERGING]				= { "diverging" },
 	[ADVICE_FETCH_SET_HEAD_WARN]			= { "fetchRemoteHEADWarn" },
diff --git a/advice.h b/advice.h
index 727dcecf4a3..fc1dc872049 100644
--- a/advice.h
+++ b/advice.h
@@ -18,7 +18,9 @@ enum advice_type {
 	ADVICE_AM_WORK_DIR,
 	ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,
 	ADVICE_COMMIT_BEFORE_MERGE,
+#ifndef WITH_BREAKING_CHANGES
 	ADVICE_DEFAULT_BRANCH_NAME,
+#endif /* WITH_BREAKING_CHANGES */
 	ADVICE_DETACHED_HEAD,
 	ADVICE_DIVERGING,
 	ADVICE_FETCH_SET_HEAD_WARN,
diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh
index 01823fd0f14..a21834043f3 100755
--- a/ci/run-build-and-tests.sh
+++ b/ci/run-build-and-tests.sh
@@ -9,7 +9,6 @@ run_tests=t
 
 case "$jobname" in
 linux-breaking-changes)
-	export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 	export WITH_BREAKING_CHANGES=YesPlease
 	;;
 linux-TEST-vars)
diff --git a/refs.c b/refs.c
index 4ff55cf24f6..e73f63ff6b8 100644
--- a/refs.c
+++ b/refs.c
@@ -627,10 +627,12 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)
 		strvec_pushf(prefixes, *p, len, prefix);
 }
 
+#ifndef WITH_BREAKING_CHANGES
 static const char default_branch_name_advice[] = N_(
 "Using '%s' as the name for the initial branch. This default branch name\n"
-"is subject to change. To configure the initial branch name to use in all\n"
-"of your new repositories, which will suppress this warning, call:\n"
+"will change to \"main\" in Git 3.0. To configure the initial branch name\n"
+"to use in all of your new repositories, which will suppress this warning,\n"
+"call:\n"
 "\n"
 "\tgit config --global init.defaultBranch <name>\n"
 "\n"
@@ -639,24 +641,32 @@ static const char default_branch_name_advice[] = N_(
 "\n"
 "\tgit branch -m <name>\n"
 );
+#endif /* WITH_BREAKING_CHANGES */
 
 char *repo_default_branch_name(struct repository *r, int quiet)
 {
 	const char *config_key = "init.defaultbranch";
 	const char *config_display_key = "init.defaultBranch";
 	char *ret = NULL, *full_ref;
+#ifndef WITH_BREAKING_CHANGES
 	const char *env = getenv("GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME");
 
 	if (env && *env)
 		ret = xstrdup(env);
-	else if (repo_config_get_string(r, config_key, &ret) < 0)
+#endif /* WITH_BREAKING_CHANGES */
+	if (!ret && repo_config_get_string(r, config_key, &ret) < 0)
 		die(_("could not retrieve `%s`"), config_display_key);
 
 	if (!ret) {
+#ifdef WITH_BREAKING_CHANGES
+		ret = xstrdup("main");
+		(void) quiet; /* Silence -Wunused-parameter */
+#else
 		ret = xstrdup("master");
 		if (!quiet)
 			advise_if_enabled(ADVICE_DEFAULT_BRANCH_NAME,
 					  _(default_branch_name_advice), ret);
+#endif /* WITH_BREAKING_CHANGES */
 	}
 
 	full_ref = xstrfmt("refs/heads/%s", ret);
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index f593c536874..7223a98773d 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -868,7 +868,7 @@ test_expect_success 'overridden default initial branch name (config)' '
 	grep nmb actual
 '
 
-test_expect_success 'advice on unconfigured init.defaultBranch' '
+test_expect_success !WITH_BREAKING_CHANGES 'advice on unconfigured init.defaultBranch' '
 	GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \
 		init unconfigured-default-branch-name 2>err &&
 	test_decode_color <err >decoded &&
@@ -883,16 +883,17 @@ test_expect_success 'advice on unconfigured init.defaultBranch disabled' '
 	test_grep ! "hint: " err
 '
 
-test_expect_success 'overridden default main branch name (env)' '
+test_expect_success !WITH_BREAKING_CHANGES 'overridden default main branch name (env)' '
 	test_config_global init.defaultBranch nmb &&
 	GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&
 	git -C main-branch-env symbolic-ref HEAD >actual &&
 	grep env actual
 '
 
 test_expect_success 'invalid default branch name' '
-	test_must_fail env GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME="with space" \
-		git init initial-branch-invalid 2>err &&
+	test_must_fail env GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+		git -c init.defaultBranch="with space" \
+			init initial-branch-invalid 2>err &&
 	test_grep "invalid branch name" err
 '
 
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 621cd31ae1d..ec6b8ebcabb 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -127,10 +127,17 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 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}
-export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+if test -z "$WITH_BREAKING_CHANGES"
+then
+	# Explicitly set the default branch name for testing, to avoid the
+	# transitory "git init" warning under --verbose.
+	: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+	export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+else
+	# Unset the default branch name that is set in many test scripts
+	# before sourcing this file.
+	unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+fi
 
 ################################################################
 # It appears that people try to run tests without building...
-- 
2.49.0.897.gfad3eb7d210
Previous: Phillip WoodNext: Junio C Hamano
Message 12 of 56 in “breaking changes: switch default initial branch name to "main"”
  1. 0/6 breaking changes: switch default initial branch name to "main"Phillip Wood, Aug 27, 2025
  2. 1/6 t0018: switch default branch name to mainPhillip Wood, Aug 27, 2025
  3. Junio C HamanoAug 27, 2025
  4. Phillip WoodAug 28, 2025
  5. Junio C HamanoAug 28, 2025
  6. brian m. carlsonAug 28, 2025
  7. 3/6 t9902: switch default branch name to mainPhillip Wood, Aug 27, 2025
  8. 2/6 t4013: switch default branch name to mainPhillip Wood, Aug 27, 2025
  9. 4/6 t0613: stop setting default initial branchPhillip Wood, Aug 27, 2025
  10. Junio C HamanoAug 27, 2025
  11. 5/6 t1403: remove dependency on GIT_TEST_DEFAULT_INITIAL_BRANCH_NAMEPhillip Wood, Aug 27, 2025
  12. 6/6 breaking-changes: switch default branch to mainPhillip Wood, Aug 27, 2025
  13. Junio C HamanoAug 27, 2025
  14. Patrick SteinhardtSep 2, 2025
  15. Phillip WoodSep 2, 2025
  16. Patrick SteinhardtSep 3, 2025
  17. Phillip WoodSep 3, 2025
  18. Patrick SteinhardtSep 3, 2025
  19. Junio C HamanoSep 3, 2025
  20. Patrick SteinhardtSep 4, 2025
  21. Phillip WoodSep 4, 2025
  22. Patrick SteinhardtSep 5, 2025
  23. Phillip WoodSep 4, 2025
  24. Johannes SchindelinAug 28, 2025
  25. 0/4 breaking changes: switch default initial branch name to "main"Phillip Wood, Sep 4, 2025
  26. 1/4 breaking-changes: switch default branch to mainPhillip Wood, Sep 4, 2025
  27. Junio C HamanoSep 4, 2025
  28. Phillip WoodSep 5, 2025
  29. Junio C HamanoSep 5, 2025
  30. 3/4 t9902: switch default branch name to mainPhillip Wood, Sep 4, 2025
  31. Junio C HamanoSep 4, 2025
  32. Phillip WoodSep 5, 2025
  33. Patrick SteinhardtSep 5, 2025
  34. Phillip WoodSep 9, 2025
  35. 2/4 t4013: switch default branch name to mainPhillip Wood, Sep 4, 2025
  36. 4/4 t0613: stop setting default initial branchPhillip Wood, Sep 4, 2025
  37. Junio C HamanoSep 4, 2025
  38. Phillip WoodSep 5, 2025
  39. Junio C HamanoSep 4, 2025
  40. Phillip WoodSep 4, 2025
  41. 0/4 breaking changes: switch default initial branch name to "main"Phillip Wood, Sep 10, 2025
  42. 1/4 breaking-changes: switch default branch to mainPhillip Wood, Sep 10, 2025
  43. 2/4 t4013: switch default branch name to mainPhillip Wood, Sep 10, 2025
  44. 3/4 t9902: switch default branch name to mainPhillip Wood, Sep 10, 2025
  45. 4/4 t0613: stop setting default initial branchPhillip Wood, Sep 10, 2025
  46. Junio C HamanoSep 10, 2025
  47. Junio C HamanoSep 17, 2025
  48. Kristoffer HaugsbakkSep 17, 2025
  49. Junio C HamanoSep 17, 2025
  50. Phillip WoodSep 17, 2025
  51. Junio C HamanoSep 17, 2025
  52. Junio C HamanoSep 17, 2025
  53. Phillip WoodSep 18, 2025
  54. 5/4 initial branch: give hints after switching the default nameJunio C Hamano, Sep 17, 2025
  55. Phillip WoodSep 18, 2025
  56. Junio C HamanoSep 18, 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.