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

[PATCH v3 2/3] branch: add 'branch.namePrefix' config param

From
VGVALERI Yoann via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 6, 2026, 13:14 UTC
Message-ID
<d51f71708ceb0263c8e10b6d7915f7a426c88f2e.1772802872.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2202.v3.git.git.1772802872.gitgitgadget@gmail.com>
From: VALERI Yoann <yoann.valeri@cea.fr>

This patch adds a new configuration parameter for the branch creation feature: 'branch.namePrefix'. It corresponds to the '--name-prefix' option of 'git branch' made as configuration parameter, and behaves exactly like it.

Signed-off-by: VALERI Yoann <yoann.valeri@cea.fr>
---
 Documentation/config/branch.adoc |  5 +++++
 branch.c                         | 18 +++++++++++-------
 t/t3200-branch.sh                | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc
index a4db9fa5c8..202c9048b4 100644
--- a/Documentation/config/branch.adoc
+++ b/Documentation/config/branch.adoc
@@ -35,6 +35,11 @@ This option defaults to `never`.
 	value of this variable will be used as the default.
 	See linkgit:git-for-each-ref[1] field names for valid values.
 
+`branch.namePrefix`::
+	When a new branch is created with `git branch`, use the provided value as
+	prefix for its name. Can be '@{current}' to use the current branch's name
+	as prefix.
+
 `branch.<name>.remote`::
 	When on branch _<name>_, it tells `git fetch` and `git push`
 	which remote to fetch from or push to.  The remote to push to
diff --git a/branch.c b/branch.c
index c24d7ce823..5fb7280d47 100644
--- a/branch.c
+++ b/branch.c
@@ -368,18 +368,22 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
 void add_branch_prefix(const char *name_prefix,
 					   const char *current_branch, struct strbuf *buf)
 {
-	int value = 0;
+	char *config_prefix = NULL;
 
-	if (!name_prefix)
-		return;
+	if (!name_prefix) {
+		if (repo_config_get_string(the_repository, "branch.namePrefix",
+								   &config_prefix))
+			return;
 
-	if (name_prefix[0] != '@') {
-		strbuf_addstr(buf, name_prefix);
-		return;
+		name_prefix = config_prefix;
 	}
 
-	if (strcmp(name_prefix, "@{current}") == 0)
+	if (name_prefix[0] != '@')
+		strbuf_addstr(buf, name_prefix);
+	else if (strcmp(name_prefix, "@{current}") == 0)
 		strbuf_addstr(buf, current_branch);
+
+    free(config_prefix);
 }
 
 /*
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 550989a2bb..847a8355cf 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1734,4 +1734,16 @@ test_expect_success 'create branch with --name-prefix' '
 	git branch -D blob-with-prefix-with-prefix
 '
 
+test_expect_success 'create branch with config prefix' '
+	test_config branch.namePrefix blob &&
+	git branch -- -with-prefix &&
+	test_must_fail git branch -- -with-prefix &&
+	test_config branch.namePrefix "@{current}" &&
+	git checkout main &&
+	git branch -- -with-prefix &&
+	test_ref_exists refs/heads/blob-with-prefix &&
+	test_ref_exists refs/heads/main-with-prefix &&
+	git branch -D blob-with-prefix main-with-prefix
+'
+
 test_done
-- 
gitgitgadget
Previous: Junio C HamanoNext: Eric Sunshine
Message 12 of 23 in “branch: add 'branch.addCurrentBranchAsPrefix' config param”
  1. branch: add 'branch.addCurrentBranchAsPrefix' config paramYoann Valeri via GitGitGadget, Feb 20, 2026
  2. Junio C HamanoFeb 20, 2026
  3. Junio C HamanoFeb 20, 2026
  4. 0/2 branch: add 'branch.addCurrentBranchAsPrefix' config paramYoann Valeri via GitGitGadget, Feb 27, 2026
  5. 1/2 branch: add 'branch.addCurrentBranchAsPrefix' config paramVALERI Yoann via GitGitGadget, Feb 27, 2026
  6. 2/2 branch: add a no-prefix optionVALERI Yoann via GitGitGadget, Feb 27, 2026
  7. Junio C HamanoFeb 27, 2026
  8. 0/3 branch: add prefixes to new branch namesYoann Valeri via GitGitGadget, Mar 6, 2026
  9. 1/3 branch: add '--name-prefix' optionVALERI Yoann via GitGitGadget, Mar 6, 2026
  10. Eric SunshineMar 7, 2026
  11. Junio C HamanoMar 8, 2026
  12. 2/3 branch: add 'branch.namePrefix' config paramVALERI Yoann via GitGitGadget, Mar 6, 2026
  13. Eric SunshineMar 7, 2026
  14. 3/3 branch: add '--no-name-prefix' optionVALERI Yoann via GitGitGadget, Mar 6, 2026
  15. Junio C HamanoMar 6, 2026
  16. Junio C HamanoMar 6, 2026
  17. Eric SunshineMar 7, 2026
  18. Junio C HamanoMar 8, 2026
  19. 0/2 branch: add prefixes to new branch namesYoann Valeri via GitGitGadget, Apr 9, 2026
  20. 1/2 branch: add '--name-prefix' optionVALERI Yoann via GitGitGadget, Apr 9, 2026
  21. 2/2 branch: add 'branch.namePrefix' config paramVALERI Yoann via GitGitGadget, Apr 9, 2026
  22. Junio C HamanoApr 9, 2026
  23. Junio C HamanoApr 9, 2026

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.