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

[PATCH v2 2/2] branch: add a no-prefix option

From
VGVALERI Yoann via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 27, 2026, 15:48 UTC
Message-ID
<0fbdf031cb9f054e023d44fd3eb3315732d527c0.1772207333.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2202.v2.git.git.1772207333.gitgitgadget@gmail.com>
From: VALERI Yoann <yoann.valeri@cea.fr>
This patch adds a '--no-prefix' option to 'git branch' to selectively
override the 'branch.addCurrentBranchAsPrefix' configuration parameter.
Signed-off-by: VALERI Yoann <yoann.valeri@cea.fr>
---
 builtin/branch.c  | 9 +++++++--
 t/t3200-branch.sh | 4 +++-
 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 2fbf2d9722..701c2a3180 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -713,7 +713,8 @@ int cmd_branch(int argc,
 {
 	/* possible actions */
 	int delete = 0, rename = 0, copy = 0, list = 0,
-	    unset_upstream = 0, show_current = 0, edit_description = 0;
+	    unset_upstream = 0, show_current = 0, edit_description = 0,
+	    no_prefix = 0;
 	const char *new_upstream = NULL;
 	int noncreate_actions = 0;
 	/* possible options */
@@ -776,6 +777,7 @@ int cmd_branch(int argc,
 		OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
 		OPT_BOOL(0, "recurse-submodules", &recurse_submodules_explicit, N_("recurse through submodules")),
 		OPT_STRING(  0 , "format", &format.format, N_("format"), N_("format to use for the output")),
+		OPT_BOOL(0, "no-prefix", &no_prefix, N_("do not add a prefix to the branch being created")),
 		OPT_END(),
 	};
 
@@ -1004,7 +1006,10 @@ int cmd_branch(int argc,
 		if (track == BRANCH_TRACK_OVERRIDE)
 			die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead"));
 
-		add_branch_prefix(start_name, branch_name, &new_branch_name);
+		if (!no_prefix)
+			add_branch_prefix(start_name, branch_name, &new_branch_name);
+		else
+			strbuf_addstr(&new_branch_name, branch_name);
 
 		if (recurse_submodules)
 			create_branches_recursively(the_repository, new_branch_name.buf,
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 496b034d0b..bc09abf725 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1725,9 +1725,11 @@ test_expect_success 'create branch with prefix' '
 	git branch branch-with-prefix &&
 	git checkout branch-with-prefix &&
 	git branch branch-with-prefix &&
+	git branch branch-with-no-prefix --no-prefix &&
 	test_ref_exists refs/heads/branch-with-prefix &&
 	test_ref_exists refs/heads/main-branch-with-prefix &&
-	test_ref_exists refs/heads/branch-with-prefix-branch-with-prefix
+	test_ref_exists refs/heads/branch-with-prefix-branch-with-prefix &&
+	test_ref_exists refs/heads/branch-with-no-prefix
 '
 
 test_done
-- 
gitgitgadget
Previous: VALERI Yoann via GitGitGadgetNext: Junio C Hamano
Message 6 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.