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

Re: [PATCH 2/2] branch: protect local upstreams from -d

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 25, 2026, 21:59 UTC
Message-ID
<xmqq33w1lv4j.fsf@gitster.g>
In-Reply-To
<d3d7a06e3d6f0c7adf9739ca496ed4012e261ac1.1787693117.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 12 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> A local branch may be fully merged into its own upstream while still
> serving as the base of a surviving stacked branch. Deleting it with
> "git branch -d" then leaves the surviving branch with a missing
> upstream.
>
> Use the existing stacked-branch protection after checking every
> requested deletion. This makes multi-branch deletion independent of
> argument order: a branch that fails its safety check remains available
> to protect its upstream. Allow -D to override the protection, and allow
> a complete stack to be deleted together.

It may be a good thing to optionally be able to do this, but changing the long-established semantics of what the '-d' option means would lead to serious breakage to the end-user workflows people depend on, I am afraid, and...

Show 8 quoted lines
> -test_expect_success 'branch -d other@{u}' '
> +test_expect_success 'branch -D other@{u}' '
>  	git checkout -t -b other main &&
> -	git branch -d @{u} &&
> +	git branch -D @{u} &&
>  	git for-each-ref refs/heads/main >actual &&
>  	test_must_be_empty actual
>  '

... having to adjust the test command sequence like this is a very clear illustration of why it is not a safe thing to do. Our change just broke what the user wanted to do, i.e., removing the branch @{u}, which they have happily been doing with '-d' while guarded by the original safety feature '-d' already had. Now they have to use '-D' to remove it unconditionally without safety -- that is not exactly progress. In addition, depending on the version of Git, our change makes 'git branch -d' behave differently, making it less predictable.

And no, a configuration variable to tweak the behaviour of '-d' is unwelcome here; it would make the behavior of the command and the option even less predictable.

Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren
Message 4 of 9 in “branch: -d protects upstream branches”
  1. 0/2 branch: -d protects upstream branchesHarald Nordgren via GitGitGadget, Aug 25, 2026
  2. 1/2 branch: move stacked branch helpersHarald Nordgren via GitGitGadget, Aug 25, 2026
  3. 2/2 branch: protect local upstreams from -dHarald Nordgren via GitGitGadget, Aug 25, 2026
  4. Junio C HamanoAug 25, 2026
  5. Harald NordgrenAug 26, 2026
  6. Tuomas AholaAug 26, 2026
  7. Harald NordgrenAug 26, 2026
  8. Junio C HamanoAug 26, 2026
  9. Elijah NewrenAug 27, 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.