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

Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Oct 27, 2026, 19:34 UTC
Message-ID
<CALnO6CC+3shDYzX3ks0wk4YuxbsdCCTbKdgHO3fEwHEkN0yx7w@mail.gmail.com>
In-Reply-To
<ba149000e13634ffcc5dc51e4d584a56@donquinleone.com>
[Liberally trimming some LLM-ish prose?]
On Sat, Oct 24, 2026 at 12:01 PM DonQuinleone <don@donquinleone.com> wrote:
Show 19 quoted lines
>
> Hi Ben, Harald,
>
> Thanks both, this has been really helpful. I've tried each suggestion
> against the reproduction script with Git 2.56.0, and here's where I've
> got to.
>
> D. Ben Knoble wrote:
> > In this case, if "topic@{upstream}" was "origin/master", though,
> > "--delete-merged=origin/*" would work, no?
>
> Yes. With push.default=current, "git switch -c topic origin/master"
> and "git push origin topic", the dry run offers to delete topic
> once the pull request is merged. So the gap
> is only for people who follow the hosting services' advice and run
> "git push -u". That's the setup I'd hoped to help, and I suspect it's a common
> one, but I agree the better long-term fix there is teaching the
> triangular setup. A document like the one you mentioned would be very
> welcome.

Yeah… I'm not too sure about the "push -u" setup, which only really works when you push to/pull from the same place. I personally want to spend my effort weaning folks off that model for triangular workflows ;)

Show 13 quoted lines
> D. Ben Knoble wrote:
> > Rereading our docs for git-branch(1), I think what this RFC is
> > looking for is
> >
> >     git branch --list --merged=origin/main | xargs git branch -d
>
> That was my hope too, but it doesn't quite get there in the
> reproduction:
>
>    $ git branch --list --merged=origin/master | xargs git branch -d
>    error: branch '*' not found
>    error: cannot delete branch 'master' used by worktree at '...'
>    error: the branch 'topic' is not fully merged

Yeah, I missed that the default output format "git branch --list" doesn't course-correct for being machine readable. But!

We can do
    git branch --list --format='%(refname:lstrip=2)' [filters] | xargs …
pretty easily!
> "git branch -d" checks topic
> against its upstream, which is gone, so it falls back to HEAD, and
> master is behind origin/master. Only
> -D [works], and that drops the check altogether.

Oh, that's interesting, I didn't know that about the deletion checks. Still, one can easily dry-run (no xargs) and then -D if needed, I suppose?

Not the best overall experience, but fairly composable, and something that could be built in to Git over time perhaps? idk.

> (The listing also
> picks up master itself, and would pick up any branch that has been
> created but not yet committed to.)

Ah, yeah. That's a bummer, and the only things I can think of are to explicitly omit it:

    | grep -v "^$(git branch --show-current)\$" | xargs …

or to simply "let it go" (even with -D Git refuses to delete the currently checked out branch). But that's a bit noisy.

> To me that points to the shape you sketched for (B), with one change:
> when -d is given list filters, the --merged commit is the proof as well
> as a filter.

At that point, I would lean towards teaching "-d" the same filters as the rest of "git branch --list" (and possibly additional ones, like --upstream-gone, if needed). That might involve some patches to make the filtering logic shareable between the 2, teaching "-d" about them, and then extending the set of filters?

Just a thought.
-- 
D. Ben Knoble
Previous: Harald NordgrenNext: D. Ben Knoble
Message 14 of 15 in “[RFC] branch: delete gone-upstream branches only when proven merged into a named ref”
  1. DonQuinleoneOct 17, 2026
  2. D. Ben KnobleOct 22, 2026
  3. Harald NordgrenOct 22, 2026
  4. D. Ben KnobleOct 24, 2026
  5. Harald NordgrenOct 24, 2026
  6. D. Ben KnobleOct 24, 2026
  7. Harald NordgrenOct 22, 2026
  8. Ben KnobleOct 22, 2026
  9. Harald NordgrenOct 22, 2026
  10. Harald NordgrenOct 22, 2026
  11. D. Ben KnobleOct 24, 2026
  12. DonQuinleoneOct 24, 2026
  13. Harald NordgrenOct 24, 2026
  14. D. Ben KnobleOct 27, 2026
  15. D. Ben KnobleOct 24, 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.