From: D. Ben Knoble Date: Tue, 27 Oct 2026 19:34:04 GMT Subject: Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref Message-ID: In-Reply-To: [Liberally trimming some LLM-ish prose?] On Sat, Oct 24, 2026 at 12:01 PM DonQuinleone wrote: > > 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 ;) > 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