git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:50 UTC

Re: [PATCH v3 1/3] branch: add '--name-prefix' option

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 8, 2026, 07:06 UTC
Message-ID
<xmqq4imqls0l.fsf@gitster.g>
In-Reply-To
<6cbb950d8bc3b647d7fff72a72f938ee369b552c.1772802872.git.gitgitgadget@gmail.com>
"VALERI Yoann via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> diff --git a/Documentation/git-branch.adoc b/Documentation/git-branch.adoc
> index c0afddc424..00967fa758 100644
> --- a/Documentation/git-branch.adoc
> +++ b/Documentation/git-branch.adoc
> @@ -17,7 +17,8 @@ git branch [--color[=<when>] | --no-color] [--show-current]
>  	   [(-r|--remotes) | (-a|--all)]
>  	   [--list] [<pattern>...]
>  git branch [--track[=(direct|inherit)] | --no-track] [-f]
> -	   [--recurse-submodules] <branch-name> [<start-point>]
> +	   [--recurse-submodules] [--name-prefix=<token>]
> +           <branch-name> [<start-point>]

The indentation of the last line seems a bit off; the previous line uses leading HT both in the original and in the updated version, but the last line uses SP indent.

Show 7 quoted lines
> @@ -64,6 +65,10 @@ Note that this will create the new branch, but it will not switch the
>  working tree to it; use `git switch <new-branch>` to switch to the
>  new branch.
>  
> +With a `--name-prefix` option, you can add a prefix to the branch to create.
> +This can either a simple name, or a token. Currently, only '@{current}' is
> +managed as token, and will use the current branch name as prefix.

"can either" -> "can either be". "managed" -> "supported".

Show 21 quoted lines
> @@ -319,6 +324,10 @@ superproject's "origin/main", but tracks the submodule's "origin/main".
>  	and the object it points at.  _<format>_ is the same as
>  	that of linkgit:git-for-each-ref[1].
>  
> +`--name-prefix <token>`::
> +	A string that will be used as prefix to the name of the new branch to
> +        create. Can be '@{current}' to use the current branch's name.
> +
>  _<branch-name>_::
>  	The name of the branch to create or delete.
>  	The new branch name must pass all checks defined by
> diff --git a/branch.c b/branch.c
> index 243db7d0fc..c24d7ce823 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -365,6 +365,23 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
>  	return 0;
>  }
>  
> +void add_branch_prefix(const char *name_prefix,
> +					   const char *current_branch, struct strbuf *buf)

Overly deep indentation here. Our tab-width is always 8, and you would align the first "const char" on these two lines.

> +{
> +	int value = 0;
Unused variable?
Show 11 quoted lines
> +	if (!name_prefix)
> +		return;
> +
> +	if (name_prefix[0] != '@') {
> +		strbuf_addstr(buf, name_prefix);
> +		return;
> +	}
> +
> +	if (strcmp(name_prefix, "@{current}") == 0)
> +		strbuf_addstr(buf, current_branch);
> +}

What happens when we need to support more than the @{current}? Will this function grow more parameters and the callers need to prepare more parameters, even if only one of them may be picked by this function? That does not smell like a sound way to make things maintainable.

Show 6 quoted lines
> diff --git a/builtin/branch.c b/builtin/branch.c
> index c577b5d20f..58631913c7 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> ...
> +		add_branch_prefix(name_prefix, start_name, &new_branch_name);

Here, `start_name` is passed as `current_branch` to `add_branch_prefix`. However, `start_name` is the `<start-point>` (e.g., another branch, a tag, or a commit). If the user runs:

    $ git branch --name-prefix=@{current} new-branch other-branch

the prefix will be `other-branch` instead of the *current* branch name as advertised in the documentation. It _may_ be how the feature was intended to work, but then the name "current" and the way the documentation describes the token are both misleading.

> +			create_branch(the_repository, new_branch_name.buf, start_name,
> +						  force, 0, reflog, quiet, track, 0);
Overly deep indentation.
Previous: Junio C HamanoNext: Yoann Valeri via GitGitGadget
Message 18 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. 2/3 branch: add 'branch.namePrefix' config paramVALERI Yoann via GitGitGadget, Mar 6, 2026
  11. 3/3 branch: add '--no-name-prefix' optionVALERI Yoann via GitGitGadget, Mar 6, 2026
  12. Junio C HamanoMar 6, 2026
  13. Junio C HamanoMar 6, 2026
  14. Eric SunshineMar 7, 2026
  15. Eric SunshineMar 7, 2026
  16. Eric SunshineMar 7, 2026
  17. Junio C HamanoMar 8, 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.