From: DonQuinleone Date: Sat, 24 Oct 2026 16:01:35 GMT Subject: Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref Message-ID: In-Reply-To: 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 a plain "git push origin topic", the dry run offers to delete topic once the pull request is merged, with no code change at all. So the gap is only for people who follow the hosting services' advice and run "git push -u", which points @{upstream} at the topic's own remote branch. 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. Harald Nordgren wrote: > Why do we need the `--into` at all? Ben has covered it, but in short: once the upstream is gone there is nothing left for --delete-merged to check against, and Junio ruled out Git choosing a substitute (HEAD, or the remote's default branch). So the commit has to come from the user, and --into was simply a way to name it. 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 The first two are just the listing format, and for-each-ref would avoid them. The third is the interesting one. "git branch -d" checks topic against its upstream, which is gone, so it falls back to HEAD, and master is behind origin/master. The commit that selected the branch is not the commit that checks it, so the proof is lost at the pipe. Only -D gets through, and that drops the check altogether. (The listing also picks up master itself, and would pick up any branch that has been created but not yet committed to.) 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. $ git branch --upstream-gone --merged=origin/master # list $ git branch -d --upstream-gone --merged=origin/master # delete In the -d form: - --merged needs an explicit commit; there is no HEAD default, so nothing is inferred; - each selected branch is deleted only if its tip is reachable from that commit, in place of the usual upstream-or-HEAD check; - a branch checked out in any worktree is still refused, and branch..deleteMerged=false would be honoured; - --upstream-gone and the existing --forked narrow the selection, so it doesn't sweep up master or a branch that hasn't been pushed yet. "git branch -d --merged=..." is rejected with the usage message today, so this adds a form rather than changing one, and --delete-merged stays exactly as it is. In the RFC I worried that this would make -d a second bulk-delete mode, but given your point about composability I now think that's the better trade. It avoids both an option that only means something next to another option and sub-values packed into one argument, which I hope answers both of your concerns. I'd welcome being told otherwise. So, updating my two questions: 1. Is "selection is not proof" an acceptable basis for deleting gone-upstream branches at all, when the proof is a commit the user names explicitly? 2. Ben, Harald: is a filtered -d, with an explicit --merged as the proof, the shape you'd want? If so, I'd start with --upstream-gone as a listing filter on its own, since it's useful without the delete half (it replaces grepping "git branch -vv" for ": gone]"), and follow with the -d part as a second patch. Thanks again, ~ Don