Thread (14 messages) 14 messages, 2 authors, 2026-04-09
STALE74d

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

From: VALERI Yoann via GitGitGadget <hidden>
Date: 2026-02-27 15:48:59
Subsystem: the rest · Maintainer: Linus Torvalds

From: VALERI Yoann <redacted>

This patch adds a '--no-prefix' option to 'git branch' to selectively
override the 'branch.addCurrentBranchAsPrefix' configuration parameter.
Signed-off-by: VALERI Yoann <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help