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

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

From
Elijah Newren <newren@gmail.com>
Date
Aug 27, 2026, 05:19 UTC
Message-ID
<CABPp-BHQvUwwA6v+5rq9=8iUWavDO1ScMVr-3ok4Zm5r_Bp2hQ@mail.gmail.com>
In-Reply-To
<d3d7a06e3d6f0c7adf9739ca496ed4012e261ac1.1787693117.git.gitgitgadget@gmail.com>

On Tue, Aug 25, 2026 at 2:30 PM Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 10 quoted lines
>
> 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.
[...]
Show 12 quoted lines
> diff --git a/Documentation/git-branch.adoc b/Documentation/git-branch.adoc
> index bfdf459329..5c2a3339b2 100644
> --- a/Documentation/git-branch.adoc
> +++ b/Documentation/git-branch.adoc
> @@ -102,7 +102,9 @@ OPTIONS
>  `--delete`::
>         Delete a branch. The branch must be fully merged in its
>         upstream branch, or in `HEAD` if no upstream was set with
> -       `--track` or `--set-upstream-to`.
> +       `--track` or `--set-upstream-to`, and must not be an upstream,
> +       directly or indirectly, of another local branch that will remain
> +       after the operation.
With this patch applied:

$ git init -q repo && cd repo $ git commit --allow-empty -m base [master (root-commit) b9a0882] base $ git branch A $ git branch B $ git branch C $ git branch --set-upstream-to=A B branch 'B' set up to track 'A'. $ git branch --set-upstream-to=B C branch 'C' set up to track 'B'. $ ~/floss/git-review/bin-wrappers/git branch -d A B error: the branch 'B' is an upstream of another branch hint: If you are sure you want to delete it, run 'git branch -D B' hint: Disable this message with "git config set advice.forceDeleteBranch false" Deleted branch A (was b9a0882).

So, C had B as an upstream and git did protect B from being deleted. That matches the claims above. However, B had A as an upstream and git didn't protect A; it deleted it. That doesn't match the claims above.

Verifying:

$ git config branch.B.merge refs/heads/A $ git rev-parse -q --verify refs/heads/A ; echo $? 1 $ git rev-parse -q --verify refs/heads/B ; echo $? b9a088270710b2494f5fa0668fc7e81a40aebd35 0

Previous: Junio C Hamano
Message 9 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.