From: Junio C Hamano <gitster@pobox.com>
To: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH 2/2] branch: protect local upstreams from -d
Date: Tue, 25 Aug 2026 14:59:08 -0700 [thread overview]
Message-ID: <xmqq33w1lv4j.fsf@gitster.g> (raw)
In-Reply-To: <d3d7a06e3d6f0c7adf9739ca496ed4012e261ac1.1787693117.git.gitgitgadget@gmail.com> (Harald Nordgren via GitGitGadget's message of "Tue, 25 Aug 2026 21:25:17 +0000")
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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...
> -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.
next prev parent reply other threads:[~2026-08-25 21:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 21:25 [PATCH 0/2] branch: -d protects upstream branches Harald Nordgren via GitGitGadget
2026-08-25 21:25 ` [PATCH 1/2] branch: move stacked branch helpers Harald Nordgren via GitGitGadget
2026-08-25 21:25 ` [PATCH 2/2] branch: protect local upstreams from -d Harald Nordgren via GitGitGadget
2026-08-25 21:59 ` Junio C Hamano [this message]
2026-08-26 6:56 ` Harald Nordgren
2026-08-26 8:46 ` Tuomas Ahola
2026-08-26 9:20 ` Harald Nordgren
2026-08-26 14:37 ` Junio C Hamano
2026-08-27 5:19 ` Elijah Newren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq33w1lv4j.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=haraldnordgren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox