Subject: [PATCH v3 3/3] branch: add '--no-name-prefix' option

From: "VALERI Yoann via GitGitGadget" <[email-masked]>
Date: Fri, 06 Mar 2026 13:14:32 +0000

From: VALERI Yoann <[email-masked]>

This patch adds the '--no-name-prefix' option to prevent adding any
prefix to the branch being created, whether through the '--name-prefix'
option or the 'branch.namePrefix' configuration parameter.
Signed-off-by: VALERI Yoann <[email-masked]>
---
 builtin/branch.c  | 9 ++++++---
 t/t3200-branch.sh | 8 ++++++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 58631913c7..204d7865d1 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_name_prefix = 0;
 	const char *new_upstream = NULL;
 	int noncreate_actions = 0;
 	/* possible options */
@@ -777,7 +778,8 @@ 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_STRING(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create")),
+		OPT_STRING_F(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create"), PARSE_OPT_NONEG),
+		OPT_BOOL(0, "no-name-prefix", &no_name_prefix, N_("do not use any prefix for the branch to create")),
 		OPT_END(),
 	};
 
@@ -1006,7 +1008,8 @@ 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(name_prefix, start_name, &new_branch_name);
+		if (!no_name_prefix)
+			add_branch_prefix(name_prefix, start_name, &new_branch_name);
 		strbuf_addstr(&new_branch_name, branch_name);
 
 		if (recurse_submodules)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 847a8355cf..cbaa45330f 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1725,13 +1725,15 @@ test_expect_success 'create branch with --name-prefix' '
 	git switch blob-with-prefix &&
 	git branch --name-prefix "@{current}" -- -with-prefix &&
 	test_must_fail git branch --name-prefix "@{current}" -- -with-prefix &&
+	git branch --name-prefix "blob" --no-name-prefix branch-with-no-prefix &&
 	test_ref_exists refs/heads/branch-with-prefix &&
 	test_ref_exists refs/heads/main-with-prefix &&
 	test_ref_exists refs/heads/blob-with-prefix &&
 	test_ref_exists refs/heads/blob-with-prefix-with-prefix &&
+	test_ref_exists refs/heads/branch-with-no-prefix &&
 	git checkout main &&
 	git branch -D branch-with-prefix main-with-prefix blob-with-prefix &&
-	git branch -D blob-with-prefix-with-prefix
+	git branch -D blob-with-prefix-with-prefix branch-with-no-prefix
 '
 
 test_expect_success 'create branch with config prefix' '
@@ -1741,9 +1743,11 @@ test_expect_success 'create branch with config prefix' '
 	test_config branch.namePrefix "@{current}" &&
 	git checkout main &&
 	git branch -- -with-prefix &&
+	git branch --no-name-prefix branch-with-no-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_ref_exists refs/heads/branch-with-no-prefix &&
+	git branch -D blob-with-prefix main-with-prefix branch-with-no-prefix
 '
 
 test_done
-- 
gitgitgadget