{"thread":{"id":"66562","subject":"[RFC] branch: delete gone-upstream branches only when proven merged into a named ref","startedAt":"2026-10-17T00:35:25Z","lastAt":"2026-10-27T19:34:04Z","messageCount":15,"participants":["DonQuinleone","D. Ben Knoble","Harald Nordgren","Ben Knoble"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"555292","messageId":"a8561fb7c2da446e7f7acc7e2a443991@donquinleone.com","threadId":"66562","inReplyTo":null,"subject":"[RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"DonQuinleone","fromEmail":"don@donquinleone.com","sentAt":"2026-10-17T00:35:25Z","receivedAt":"2026-10-17T00:35:25Z","isPatch":false,"sender":{"key":"don@donquinleone.com","avatar":null},"body":"Hi all,\n\nThis is my first time posting to the list, so good to meet everyone,\nand thanks in advance for bearing with me.\n\nI've just noticed that \"git branch --delete-merged\" is now available,\nand that it never deletes a topic in the workflow that hosting\nservices (e.g. GitHub) encourage. Before writing a patch, I wanted to\nask how the list might consider closing that gap.\n\nIn that workflow, the topic tracks and pushes to a branch of its own\nname; when the pull request is merged with a merge commit, the server\ndeletes that branch. With master as of c51408889:\n\n  $ git push -u origin topic\n       ... merged on the server, and origin's topic deleted ...\n\n  $ git fetch origin\n  $ git branch --dry-run --delete-merged 'origin/*'\n       ... spared, as pushing would update the upstream ...\n\n  $ git fetch --prune origin\n  $ git branch -vv\n  * master 61e9886 [origin/master: behind 2] base\n    topic  87d0c48 [origin/topic: gone] topic work\n  $ git branch --dry-run --delete-merged 'origin/*'\n       ... skipped, because the upstream is gone ...\n  $ git merge-base --is-ancestor topic origin/master && echo merged\n  merged\n\nSo the branch is provably merged, but at no point in this workflow\nwill --delete-merged remove it. A script reproducing this is at the\nbottom.\n\nFrom reading back through the archives, this is deliberate. When v7\nof the series fell back to the remote's default branch for a gone\nupstream, Junio wrote [1]:\n\n> If the upstream itself is gone, removing anything based on some other\n> criteria cannot by definition a \"safety check\".\n\nI agree that a vanished upstream proves nothing, so I would like to\npropose separating selection from proof:\n\n\"Upstream gone\" may select a candidate, but it is never proof. The\nonly proof is that the branch tip is reachable from a ref the user\nnames explicitly, so nothing is inferred: neither HEAD, nor the\nremote's default branch.\n\nI can see two possible shapes.\n\n(A) A modifier on --delete-merged:\n\n  $ git branch --delete-merged 'origin/*' --into origin/master\n\nBranches whose upstream matches the pattern but no longer exists would\nbecome candidates, and would be deleted only if their tip is reachable\nfrom the named commit. check_branch_commit() would be handed that\ncommit in place of HEAD, as suggested on v7 [1]. Branches whose\nupstream still exists would be judged exactly as today, and the\nworktree, stacked-branch and deleteMerged=false exclusions would still\napply.\n\n(B) Composable filters on -d:\n\n  $ git branch --upstream-gone --merged=origin/master      # preview\n  $ git branch -d --upstream-gone --merged=origin/master   # delete\n\n--upstream-gone would be useful on its own for listing (today the\nusual approach is to grep \"git branch -vv\" for \": gone]\"). But it\nturns -d into a second bulk-delete mode beside --delete-merged, and\n--merged defaults to HEAD when it comes last, so a forgotten argument\nwould quietly bring back HEAD as the proxy.\n\nI lean towards (A) because it is small and keeps every existing\nprotection, but I'd rather settle the shape here than assume anything.\n\nSo:\n\n 1. Is \"selection is not proof\" an acceptable basis for touching\n    gone-upstream branches?\n\n 2. (A), (B), or something else? If (A), is there a better name than\n    --into (--merged-into?), and should it stay limited to branches\n    whose upstream is gone?\n\nI would leave squashing and rebasing out of scope, in keeping with\n--delete-merged staying \"one stable and strict\" operation [2]. I've\nCc'd Harald, as this relates closely to his in-flight --delete-merged\ntopics [3][4], and Phillip, who reviewed the series.\n\nThanks in advance. Look forward to hearing what people think.\n\n~ Don\n\n[1] https://lore.kernel.org/git/xmqq5x4sn393.fsf@gitster.g/\n[2] https://lore.kernel.org/git/xmqqy0c21gq1.fsf@gitster.g/\n[3] https://lore.kernel.org/git/pull.2428.v2.git.git.1791102886740.gitgitgadget@gmail.com/\n[4] https://lore.kernel.org/git/94a6d23f8b96d4a07fb58c71f4a2f7dc4d3055bc.1791711665.git.gitgitgadget@gmail.com/\n\n-- >8 --\n#!/bin/sh\nset -e\nexport GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1\nexport GIT_AUTHOR_NAME=A GIT_AUTHOR_EMAIL=a@example.com\nexport GIT_COMMITTER_NAME=C GIT_COMMITTER_EMAIL=c@example.com\ncd \"$(mktemp -d)\"\ngit init -q --bare -b master origin.git\ngit clone -q origin.git work 2>/dev/null && cd work\ngit commit -q --allow-empty -m base && git push -q origin HEAD:master\ngit switch -q -c topic && git commit -q --allow-empty -m \"topic work\"\ngit push -q -u origin topic 2>/dev/null && git switch -q master\ngit clone -q ../origin.git ../server && (cd ../server &&\n\tgit merge -q --no-ff -m \"Merge topic\" origin/topic &&\n\tgit push -q origin master :topic)\necho \"after fetch:\";         git fetch -q\ngit branch --dry-run --delete-merged 'origin/*'\necho \"after fetch --prune:\"; git fetch -q --prune\ngit branch --dry-run --delete-merged 'origin/*'\ngit merge-base --is-ancestor topic origin/master && echo merged\n\n"},{"id":"555861","messageId":"CALnO6CAsCvJRywkw0WpO1nEhL+yU2-r_4Z2AHdJch1m=NK8=TA@mail.gmail.com","threadId":"66562","inReplyTo":"a8561fb7c2da446e7f7acc7e2a443991@donquinleone.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-22T12:46:22Z","receivedAt":"2026-10-22T12:46:22Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Fri, Oct 16, 2026 at 8:41 PM DonQuinleone <don@donquinleone.com> wrote:\n>\n> Hi all,\n>\n> This is my first time posting to the list, so good to meet everyone,\n> and thanks in advance for bearing with me.\n>\n> I've just noticed that \"git branch --delete-merged\" is now available,\n> and that it never deletes a topic in the workflow that hosting\n> services (e.g. GitHub) encourage. Before writing a patch, I wanted to\n> ask how the list might consider closing that gap.\n>\n> In that workflow, the topic tracks and pushes to a branch of its own\n> name; when the pull request is merged with a merge commit, the server\n> deletes that branch. With master as of c51408889:\n>\n>   $ git push -u origin topic\n>        ... merged on the server, and origin's topic deleted ...\n>\n>   $ git fetch origin\n>   $ git branch --dry-run --delete-merged 'origin/*'\n>        ... spared, as pushing would update the upstream ...\n>\n>   $ git fetch --prune origin\n>   $ git branch -vv\n>   * master 61e9886 [origin/master: behind 2] base\n>     topic  87d0c48 [origin/topic: gone] topic work\n>   $ git branch --dry-run --delete-merged 'origin/*'\n>        ... skipped, because the upstream is gone ...\n>   $ git merge-base --is-ancestor topic origin/master && echo merged\n>   merged\n>\n> So the branch is provably merged, but at no point in this workflow\n> will --delete-merged remove it. A script reproducing this is at the\n> bottom.\n>\n> From reading back through the archives, this is deliberate. When v7\n> of the series fell back to the remote's default branch for a gone\n> upstream, Junio wrote [1]:\n>\n> > If the upstream itself is gone, removing anything based on some other\n> > criteria cannot by definition a \"safety check\".\n\nHm. I had a hard time following the \"--delete-merged\" series, so this\nmay come out of ignorance, but: we are asking Git to delete things\nmerged into \"origin/*\"; I'm not sure why we'd need to consult\n\"topic@{upstream}\" to see that \"topic\" is merged into \"origin/master\"\nhere, since there's a merge commit with \"topic\" as one of the\nparents?!\n\nAh, but the manual seems to contradict my (personal) \"natural\" reading\nof the command: \"--delete-merged\" actually deletes branches whose tip\nis reachable from their upstream (when that upstream matches the given\npattern). So, phooey. In this case, if \"topic@{upstream}\" was\n\"origin/master\", though, \"--delete-merged=origin/*\" would work, no?\nIncidentally, I find it a shame that GitHub's documentation encourages\na triangular workflow (whether or not there is a fork remote involved)\nwithout talking about how to configure Git to help you: fork or not,\nif you push to a topic branch but merge to another, it's extremely\nhandy to use push.default=current or some variant so that\n\n- @{upstream} is the place you'll merge\n- @{push} is the place you push\n\nand suddenly \"git pull [--rebase]\" does the right thing, \"git status\"\n(esp. with the new \"status.compareBranches\") can tell you where you\nare relative to both places of interest, etc.\n\nIOW, \"git push -u origin topic\" makes upstream configuration very odd\nin the GitHub-ish workflow!\n\n> I agree that a vanished upstream proves nothing, so I would like to\n> propose separating selection from proof:\n>\n> \"Upstream gone\" may select a candidate, but it is never proof. The\n> only proof is that the branch tip is reachable from a ref the user\n> names explicitly, so nothing is inferred: neither HEAD, nor the\n> remote's default branch.\n\nI'll refrain from commenting on whether we want to make\n\"--delete-merged\" delete a branch here or whether we need an\nadditional mechanism for including topics whose upstream disappeared,\nbut Git's CLI is already a bit notorious, so whatever interface we\ndesign should be composable.\n\n> I can see two possible shapes.\n>\n> (A) A modifier on --delete-merged:\n>\n>   $ git branch --delete-merged 'origin/*' --into origin/master\n>\n> Branches whose upstream matches the pattern but no longer exists would\n> become candidates, and would be deleted only if their tip is reachable\n> from the named commit. check_branch_commit() would be handed that\n> commit in place of HEAD, as suggested on v7 [1]. Branches whose\n> upstream still exists would be judged exactly as today, and the\n> worktree, stacked-branch and deleteMerged=false exclusions would still\n> apply.\n\nA standalone modifier for another option makes the interface (IMO)\ncomplex; now we have to explain that \"--into\" only makes sense in some\ncontexts (and add code to bail out).\n\nI would much rather see more --option=value,value,value syntaxes, like\n\n     git branch --delete-merged='origin/*,into:origin/master'\n\nIf we gain another form, we don't need new --options. We would also be\nable to say \"--delete-merged=into:origin\" and DWIM without any\nupstream configuration (or, with push.default=simple, even when\nupstream is just the place one pushed to).\n\n> (B) Composable filters on -d:\n>\n>   $ git branch --upstream-gone --merged=origin/master      # preview\n>   $ git branch -d --upstream-gone --merged=origin/master   # delete\n>\n> --upstream-gone would be useful on its own for listing (today the\n> usual approach is to grep \"git branch -vv\" for \": gone]\"). But it\n> turns -d into a second bulk-delete mode beside --delete-merged, and\n> --merged defaults to HEAD when it comes last, so a forgotten argument\n> would quietly bring back HEAD as the proxy.\n\nIn a world where we didn't have --delete-merged, this would have been\nthe natural fit, I think. Imagine:\n\n    git branch -d --merged-upstream=<pat>\n    git branch -d --merged-into=<pat>\n\netc. Or even \"--merged=upstream:<pat>,into:<pat>\". Then we could also\ntake some of the \"--list\" filters and make them apply to \"-d\". In the\nambiguous case of a ref named, say, \"--contains\", we could use \"--\" to\nseparate options from named branches to delete.\n\n"},{"id":"555867","messageId":"CAHwyqnWi3MCvAw-sNrn6k3ht1tpUfmNg18BAvEThKthen5Dwmw@mail.gmail.com","threadId":"66562","inReplyTo":"CALnO6CAsCvJRywkw0WpO1nEhL+yU2-r_4Z2AHdJch1m=NK8=TA@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-22T13:43:34Z","receivedAt":"2026-10-22T13:43:34Z","isPatch":false,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> Ah, but the manual seems to contradict my (personal) \"natural\" reading\n> of the command: \"--delete-merged\" actually deletes branches whose tip\n> is reachable from their upstream (when that upstream matches the given\n> pattern). So, phooey. In this case, if \"topic@{upstream}\" was\n> \"origin/master\", though, \"--delete-merged=origin/*\" would work, no?\n> Incidentally, I find it a shame that GitHub's documentation encourages\n> a triangular workflow (whether or not there is a fork remote involved)\n> without talking about how to configure Git to help you: fork or not,\n> if you push to a topic branch but merge to another, it's extremely\n> handy to use push.default=current or some variant so that\n>\n> - @{upstream} is the place you'll merge\n> - @{push} is the place you push\n>\n> and suddenly \"git pull [--rebase]\" does the right thing, \"git status\"\n> (esp. with the new \"status.compareBranches\") can tell you where you\n> are relative to both places of interest, etc.\n>\n> IOW, \"git push -u origin topic\" makes upstream configuration very odd\n> in the GitHub-ish workflow!\n\nFully agree!\n\nI would say most workflows are triangular on the underlying level,\neven if the developer is not aware of it. If you work with GitHub PRs\nor GitLab's MR, then you are engaging in a triangular workflow.\n\nI picked up some important tricks for visualizing the triangular on\nthis mailing list. But most of our users are not on the mailing list.\nBut what we can and should do is to make git itself clearer, so they\nhave a chance of intuiting it. I think for example that\n\n    push.default=current\n\nshould likely be the default. And many people would have a better time with\n\n    branch.autosetupmerge=inherit\n\nwhich gives you upstream/master as @{u} from the beginning, and then\nyou likely never abandon that if you are a regular GitHub user.\n\nThis is also why I feel strongly about this as default\n(https://lore.kernel.org/git/pull.2458.git.git.1792437798463.gitgitgadget@gmail.com/):\n\n    status.comparebranches=@{upstream} @{push}\n\nbecause it's confusing to switch tracking away from your \"own branch\"\nto upstream/master, if that means losing the waypoint of how things\ncompare against @{push}.\n\n\nHarald\n\n"},{"id":"555870","messageId":"CAHwyqnU-BEtOPdVbBXtuEYtFYuL3MqC9nUQeP_Puvq5bsoWEAQ@mail.gmail.com","threadId":"66562","inReplyTo":"CALnO6CAsCvJRywkw0WpO1nEhL+yU2-r_4Z2AHdJch1m=NK8=TA@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-22T14:38:22Z","receivedAt":"2026-10-22T14:38:22Z","isPatch":false,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> I would much rather see more --option=value,value,value syntaxes, like\n>\n>      git branch --delete-merged='origin/*,into:origin/master'\n\nThis feels completely chaotic to me and becomes a kitchen sink :)\n\n\nHarald\n\n"},{"id":"555883","messageId":"3EF4DA22-6739-46FA-8028-74EED08BB931@gmail.com","threadId":"66562","inReplyTo":"CAHwyqnU-BEtOPdVbBXtuEYtFYuL3MqC9nUQeP_Puvq5bsoWEAQ@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-22T17:14:27Z","receivedAt":"2026-10-22T17:14:27Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"\n> Le 22 oct. 2026 à 10:39, Harald Nordgren <haraldnordgren@gmail.com> a écrit :\n> \n> ﻿\n>> \n>> I would much rather see more --option=value,value,value syntaxes, like\n>> \n>>     git branch --delete-merged='origin/*,into:origin/master'\n> \n> This feels completely chaotic to me and becomes a kitchen sink :)\n\nBut is it better or worse than the kitchen sink of\n\n    git branch --delete-merged origin/* --into origin/master […]\n\n? Hm. I suppose if you didn’t like commas, we could allow\nrepeating the option to « stack » instead of replacing.\n\nBut I get the feeling that’s not what you took issue with ;)\n"},{"id":"555890","messageId":"CAHwyqnWJOk9FCGkPi8yWOFq5vr-CMWNhn=wBAifx9Gfn+1bMzA@mail.gmail.com","threadId":"66562","inReplyTo":"3EF4DA22-6739-46FA-8028-74EED08BB931@gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-22T17:52:02Z","receivedAt":"2026-10-22T17:52:02Z","isPatch":false,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"On Thu, Oct 22, 2026 at 7:14 PM Ben Knoble <ben.knoble@gmail.com> wrote:\n>\n>\n> > Le 22 oct. 2026 à 10:39, Harald Nordgren <haraldnordgren@gmail.com> a écrit :\n> >\n> > ﻿\n> >>\n> >> I would much rather see more --option=value,value,value syntaxes, like\n> >>\n> >>     git branch --delete-merged='origin/*,into:origin/master'\n> >\n> > This feels completely chaotic to me and becomes a kitchen sink :)\n>\n> But is it better or worse than the kitchen sink of\n>\n>     git branch --delete-merged origin/* --into origin/master […]\n>\n> ? Hm. I suppose if you didn’t like commas, we could allow\n> repeating the option to « stack » instead of replacing.\n>\n> But I get the feeling that’s not what you took issue with ;)\n\nNo, this is the part I take issue with:\n\n    --delete-merged=into:origin/master\n\nIt feels akin to hacking some code into the arg like a\n\n    find . -exec something\n\n\nHarald\n\n"},{"id":"555891","messageId":"CAHwyqnWi6E=idoP2+1FdeEE4-o3D20xJfsc4Dutt6R30c===xQ@mail.gmail.com","threadId":"66562","inReplyTo":"CAHwyqnWJOk9FCGkPi8yWOFq5vr-CMWNhn=wBAifx9Gfn+1bMzA@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-22T17:53:25Z","receivedAt":"2026-10-22T17:53:25Z","isPatch":false,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"Why do we need the `--into` at all?\n\n\nHarald\n\n"},{"id":"556152","messageId":"CALnO6CAxzo5gxpWkfjtvskTVjmWWD4oFE2QKyFMMo7JZUCkBmg@mail.gmail.com","threadId":"66562","inReplyTo":"CAHwyqnWi3MCvAw-sNrn6k3ht1tpUfmNg18BAvEThKthen5Dwmw@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-24T13:14:21Z","receivedAt":"2026-10-24T13:14:21Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Thu, Oct 22, 2026 at 9:44 AM Harald Nordgren\n<haraldnordgren@gmail.com> wrote:\n>\n> > Ah, but the manual seems to contradict my (personal) \"natural\" reading\n> > of the command: \"--delete-merged\" actually deletes branches whose tip\n> > is reachable from their upstream (when that upstream matches the given\n> > pattern). So, phooey. In this case, if \"topic@{upstream}\" was\n> > \"origin/master\", though, \"--delete-merged=origin/*\" would work, no?\n> > Incidentally, I find it a shame that GitHub's documentation encourages\n> > a triangular workflow (whether or not there is a fork remote involved)\n> > without talking about how to configure Git to help you: fork or not,\n> > if you push to a topic branch but merge to another, it's extremely\n> > handy to use push.default=current or some variant so that\n> >\n> > - @{upstream} is the place you'll merge\n> > - @{push} is the place you push\n> >\n> > and suddenly \"git pull [--rebase]\" does the right thing, \"git status\"\n> > (esp. with the new \"status.compareBranches\") can tell you where you\n> > are relative to both places of interest, etc.\n> >\n> > IOW, \"git push -u origin topic\" makes upstream configuration very odd\n> > in the GitHub-ish workflow!\n>\n> Fully agree!\n>\n> I would say most workflows are triangular on the underlying level,\n> even if the developer is not aware of it. If you work with GitHub PRs\n> or GitLab's MR, then you are engaging in a triangular workflow.\n>\n> I picked up some important tricks for visualizing the triangular on\n> this mailing list. But most of our users are not on the mailing list.\n\nYep. Maybe I'll start writing a \"triangular workflow\" document à la\nJulia's work… going on the todo list, at any rate.\n\n> But what we can and should do is to make git itself clearer, so they\n> have a chance of intuiting it. I think for example that\n>\n>     push.default=current\n>\n> should likely be the default.\n\nIIUC, the last change in this area was controversial. I worry that\nchanges here now would have to get through \"scar tissue\" (both of Git\ncontributors *and* users). At any rate, it would probably want to be a\nmajor version release, and I understand it's probably too late to\ndiscuss flipping that in 3.0?\n\n> And many people would have a better time with\n>\n>     branch.autosetupmerge=inherit\n>\n> which gives you upstream/master as @{u} from the beginning, and then\n> you likely never abandon that if you are a regular GitHub user.\n\nHm. Since I mostly do\n\n    git switch -c topic origin\n\nor similar, I'm ok with the default (=true). With inherit, the primary\nhelp is to folks who do\n\n    git switch -c topic main\n\nor something, right? But the documentation doesn't say what happens\nwhen inherit is used with a remote-tracking branch as a starting point\n(which has no upstream to copy from).\n\n> This is also why I feel strongly about this as default\n> (https://lore.kernel.org/git/pull.2458.git.git.1792437798463.gitgitgadget@gmail.com/):\n>\n>     status.comparebranches=@{upstream} @{push}\n>\n> because it's confusing to switch tracking away from your \"own branch\"\n> to upstream/master, if that means losing the waypoint of how things\n> compare against @{push}.\n\nYeah, I'll try and reply in that thread shortly.\n\n-- \nD. Ben Knoble\n\n"},{"id":"556153","messageId":"CALnO6CAd62NqWMw66UT7mDuM71rcSBFidrr5f+PfR2jA9D9v=g@mail.gmail.com","threadId":"66562","inReplyTo":"CAHwyqnWJOk9FCGkPi8yWOFq5vr-CMWNhn=wBAifx9Gfn+1bMzA@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-24T13:18:30Z","receivedAt":"2026-10-24T13:18:30Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Thu, Oct 22, 2026 at 1:52 PM Harald Nordgren\n<haraldnordgren@gmail.com> wrote:\n>\n> On Thu, Oct 22, 2026 at 7:14 PM Ben Knoble <ben.knoble@gmail.com> wrote:\n> >\n> > > Le 22 oct. 2026 à 10:39, Harald Nordgren <haraldnordgren@gmail.com> a écrit :\n> > >>\n> > >> I would much rather see more --option=value,value,value syntaxes, like\n> > >>\n> > >>     git branch --delete-merged='origin/*,into:origin/master'\n> > >\n> > > This feels completely chaotic to me and becomes a kitchen sink :)\n> >\n> > But is it better or worse than the kitchen sink of\n> >\n> >     git branch --delete-merged origin/* --into origin/master […]\n> >\n> > ? Hm. I suppose if you didn’t like commas, we could allow\n> > repeating the option to « stack » instead of replacing.\n> >\n> > But I get the feeling that’s not what you took issue with ;)\n>\n> No, this is the part I take issue with:\n>\n>     --delete-merged=into:origin/master\n>\n> It feels akin to hacking some code into the arg like a\n>\n>     find . -exec something\n\nWell, I find it more composable than tacking on additional modifiers\nvia --long-options (which incidentally make the synopsis more\ncomplicated, and add lots of \"this option only makes sense in this\ncontext\" checks)---that \"context-sensitive\" nature seems to me to make\nour interface quite a bit more confusing. See the \"INCOMPATIBLE\nOPTIONS\" section of git-rebase, for example!\n\n-- \nD. Ben Knoble\n\n"},{"id":"556154","messageId":"CALnO6CAAoMLZP4MBzgBa96RYMMReyxKXObb2JELqkBe=LBUVLg@mail.gmail.com","threadId":"66562","inReplyTo":"CAHwyqnWi6E=idoP2+1FdeEE4-o3D20xJfsc4Dutt6R30c===xQ@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-24T13:35:17Z","receivedAt":"2026-10-24T13:35:17Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Thu, Oct 22, 2026 at 1:54 PM Harald Nordgren\n<haraldnordgren@gmail.com> wrote:\n>\n> Why do we need the `--into` at all?\n\nThis message trimmed so much context that I had to visit lore to see\nwhat it replied to…\n\n…but I think you'll find the answer in the original mail, which\ndiscusses how --delete-merged works when the upstream branch is\ndeleted (e.g., via GitHub's \"automatically delete head branches\"\nsetting, which is useful to enable IMO). In that case, even though the\nbranch was merged, the local topic is not a candidate for deletion\n(because we can't be sure about what happened to its upstream).\n\nSo the proposal is originally either\n\n* add a modifier to --delete-merged that allows considering such topics\n* add a modifier to \"git branch --delete\" for the same\n\nTo which I've suggested that either\n\n* delete-merged should be allowed to work in this case, possibly via a\nspecial syntax, modifier option, etc.\n* branch --delete should be allowed to filter branches, in which case\nwe could even migrate some of --delete-merged into that form\n\nIn hindsight, an *even more composable* interface would have been to\nteach --list mode how to filter the appropriate merged branches (which\nwe could then add to for this RFC) and encourage\n\n    git branch --list [filters] | xargs git branch -d\n\npossibly adding a -z option if needed (which my read of\ngit-check-ref-format(1) suggests is unnecessary)? In which case\n--delete-merged could be something like\n\n    git branch --list --merged-upstream=origin/main | xargs git branch -d\n\nwhere --merged-upstream=<commit> lists all branches whose upstream\nconfiguration is reachable from <commit> (and I suppose you might need\n\"-D\" in some cases, hence the --delete-merged --dry-run form today,\nwhich would be \"just omit the pipe to xargs\" in this version). And the\ndelete-merged branch filter would still work, since --list takes\npattern arguments! Hm. I'm starting more and more to feel like this is\na missed opportunity.\n\nRereading our docs for git-branch(1), I think what this RFC is looking for is\n\n    git branch --list --merged=origin/main | xargs git branch -d\n\nwhich should already list (and then delete) local branches whose tip\nis reachable from origin/main. And it would be sure nice if that\ncombined with --delete-merged, but since they are separate forms, more\nwork is needed. If we had the --merged-upstream filter, we'd simply do\n\n    git branch --list --merged{,-upstream}=origin/main | xargs git branch -d\n\n:)\n\n-- \nD. Ben Knoble\n\n"},{"id":"556158","messageId":"CAHwyqnVV86Satk=_on=oG6ZVnSF5GdUWmpP0_wE74HRKGpKfSg@mail.gmail.com","threadId":"66562","inReplyTo":"CALnO6CAxzo5gxpWkfjtvskTVjmWWD4oFE2QKyFMMo7JZUCkBmg@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-24T14:52:11Z","receivedAt":"2026-10-24T14:52:11Z","isPatch":false,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> > I would say most workflows are triangular on the underlying level,\n> > even if the developer is not aware of it. If you work with GitHub PRs\n> > or GitLab's MR, then you are engaging in a triangular workflow.\n> >\n> > I picked up some important tricks for visualizing the triangular on\n> > this mailing list. But most of our users are not on the mailing list.\n>\n> Yep. Maybe I'll start writing a \"triangular workflow\" document à la\n> Julia's work… going on the todo list, at any rate.\n\nThat would be cool!\n\n> > But what we can and should do is to make git itself clearer, so they\n> > have a chance of intuiting it. I think for example that\n> >\n> >     push.default=current\n> >\n> > should likely be the default.\n>\n> IIUC, the last change in this area was controversial. I worry that\n> changes here now would have to get through \"scar tissue\" (both of Git\n> contributors *and* users). At any rate, it would probably want to be a\n> major version release, and I understand it's probably too late to\n> discuss flipping that in 3.0?\n\nWould be interesting to switch to \"current\" as default for 3.0.\n\nBut I don't know all the history there. \"Simple\" does feel like a\ncompromise in that it's not really good for anyone :)\n\n> > And many people would have a better time with\n> >\n> >     branch.autosetupmerge=inherit\n> >\n> > which gives you upstream/master as @{u} from the beginning, and then\n> > you likely never abandon that if you are a regular GitHub user.\n>\n> Hm. Since I mostly do\n>\n>     git switch -c topic origin\n\nMe too (or it least I used to before I started experimenting with\ninherit) although for currying purposes I always spell it\n\n    git switch origin -c topic\n\nsince I want to have the most variable part last, so e.g. \"git sw...\"\nauto-completes by pressing the up key in zsh to give me almost the\nright thing and I can just erase and re-fill the last part of the\ncommand. (This whole paragraph is a complete side-note.)\n\n> or similar, I'm ok with the default (=true). With inherit, the primary\n> help is to folks who do\n>\n>     git switch -c topic main\n>\n> or something, right? But the documentation doesn't say what happens\n> when inherit is used with a remote-tracking branch as a starting point\n> (which has no upstream to copy from).\n\nIt's simpler than that, since you can skip the \"main\" part, which by\nthe way I don't think is well understood by regular users.\n\nThis is the beautiful part: since you start with a good upstream when\ncloning (origin/main) you never need to leave it, *and* you never need\nto even specify it when branching throughout the lifecycle of the\nrepo.\n\n\nHarald\n\n"},{"id":"556169","messageId":"CALnO6CCCHAG5UZi5w3znr5Uiruk8RvF2QZYu+QcVRzenyesu-w@mail.gmail.com","threadId":"66562","inReplyTo":"CAHwyqnVV86Satk=_on=oG6ZVnSF5GdUWmpP0_wE74HRKGpKfSg@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-24T15:30:19Z","receivedAt":"2026-10-24T15:30:19Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Sat, Oct 24, 2026 at 10:52 AM Harald Nordgren\n<haraldnordgren@gmail.com> wrote:\n>\n> > > But what we can and should do is to make git itself clearer, so they\n> > > have a chance of intuiting it. I think for example that\n> > >\n> > >     push.default=current\n> > >\n> > > should likely be the default.\n> >\n> > IIUC, the last change in this area was controversial. I worry that\n> > changes here now would have to get through \"scar tissue\" (both of Git\n> > contributors *and* users). At any rate, it would probably want to be a\n> > major version release, and I understand it's probably too late to\n> > discuss flipping that in 3.0?\n>\n> Would be interesting to switch to \"current\" as default for 3.0.\n>\n> But I don't know all the history there. \"Simple\" does feel like a\n> compromise in that it's not really good for anyone :)\n\nI can certainly agree it doesn't seem that way to me! OTOH, it's being\nused by presumably most of our users today… so… \"good\" is perhaps a\nmatter of how you define it ;)\n\nYou and I see \"good\" as \"helping folks take advantage of all Git has\nto offer\", while some of our users are content \"as simple as possible\nwithout learning more that lets me get the job done.\" Neither is\nbetter than the other, so even if I too wish push.default=simple were\nnot the default, I can't say it isn't good for anyone :/\n\n> > > And many people would have a better time with\n> > >\n> > >     branch.autosetupmerge=inherit\n> > >\n> > > which gives you upstream/master as @{u} from the beginning, and then\n> > > you likely never abandon that if you are a regular GitHub user.\n> >\n> > Hm. Since I mostly do\n> >\n> >     git switch -c topic origin\n>\n> Me too (or it least I used to before I started experimenting with\n> inherit) although for currying purposes I always spell it\n>\n>     git switch origin -c topic\n>\n> since I want to have the most variable part last, so e.g. \"git sw...\"\n> auto-completes by pressing the up key in zsh to give me almost the\n> right thing and I can just erase and re-fill the last part of the\n> command. (This whole paragraph is a complete side-note.)\n\nContinuing the tangent, then, that's now \"git help cli\" describes Git\nworking, and one day someone might make things stricter and break you\n;)\n\n> > or similar, I'm ok with the default (=true). With inherit, the primary\n> > help is to folks who do\n> >\n> >     git switch -c topic main\n> >\n> > or something, right? But the documentation doesn't say what happens\n> > when inherit is used with a remote-tracking branch as a starting point\n> > (which has no upstream to copy from).\n>\n> It's simpler than that, since you can skip the \"main\" part, which by\n> the way I don't think is well understood by regular users.\n\nAh, I also didn't understand that. But that only works if (a) you're\nalready on a branch whose upstream is main, a reasonable assumption,\nand (b) you don't care if you have to type \"git reset --hard\n@{upstream}\" afterwards, right? If I am on some topic branch that's\nahead of upstream, then my new branch is at the same commit, which is\nnot usually what I want. In some projects and workflows that's a\nreasonable thing to do, though!\n\nOne advantage for me of specifying origin or w/e is that I get to\nstart with a clean slate/known good starting point, since the reset\nhappens automatically.\n\n-- \nD. Ben Knoble\n\n"},{"id":"556171","messageId":"ba149000e13634ffcc5dc51e4d584a56@donquinleone.com","threadId":"66562","inReplyTo":"CALnO6CAAoMLZP4MBzgBa96RYMMReyxKXObb2JELqkBe=LBUVLg@mail.gmail.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"DonQuinleone","fromEmail":"don@donquinleone.com","sentAt":"2026-10-24T16:01:35Z","receivedAt":"2026-10-24T16:01:35Z","isPatch":false,"sender":{"key":"don@donquinleone.com","avatar":null},"body":"Hi Ben, Harald,\n\nThanks both, this has been really helpful. I've tried each suggestion\nagainst the reproduction script with Git 2.56.0, and here's where I've\ngot to.\n\nD. Ben Knoble wrote:\n> In this case, if \"topic@{upstream}\" was \"origin/master\", though,\n> \"--delete-merged=origin/*\" would work, no?\n\nYes. With push.default=current, \"git switch -c topic origin/master\"\nand a plain \"git push origin topic\", the dry run offers to delete topic\nonce the pull request is merged, with no code change at all. So the gap\nis only for people who follow the hosting services' advice and run\n\"git push -u\", which points @{upstream} at the topic's own remote\nbranch. That's the setup I'd hoped to help, and I suspect it's a common\none, but I agree the better long-term fix there is teaching the\ntriangular setup. A document like the one you mentioned would be very\nwelcome.\n\nHarald Nordgren wrote:\n> Why do we need the `--into` at all?\n\nBen has covered it, but in short: once the upstream is gone there is\nnothing left for --delete-merged to check against, and Junio ruled out\nGit choosing a substitute (HEAD, or the remote's default branch). So\nthe commit has to come from the user, and --into was simply a way to\nname it.\n\nD. Ben Knoble wrote:\n> Rereading our docs for git-branch(1), I think what this RFC is\n> looking for is\n> >     git branch --list --merged=origin/main | xargs git branch -d\n\nThat was my hope too, but it doesn't quite get there in the\nreproduction:\n\n  $ git branch --list --merged=origin/master | xargs git branch -d\n  error: branch '*' not found\n  error: cannot delete branch 'master' used by worktree at '...'\n  error: the branch 'topic' is not fully merged\n\nThe first two are just the listing format, and for-each-ref would avoid\nthem. The third is the interesting one. \"git branch -d\" checks topic\nagainst its upstream, which is gone, so it falls back to HEAD, and\nmaster is behind origin/master. The commit that selected the branch is\nnot the commit that checks it, so the proof is lost at the pipe. Only\n-D gets through, and that drops the check altogether. (The listing also\npicks up master itself, and would pick up any branch that has been\ncreated but not yet committed to.)\n\nTo me that points to the shape you sketched for (B), with one change:\nwhen -d is given list filters, the --merged commit is the proof as well\nas a filter.\n\n  $ git branch --upstream-gone --merged=origin/master      # list\n  $ git branch -d --upstream-gone --merged=origin/master   # delete\n\nIn the -d form:\n\n - --merged needs an explicit commit; there is no HEAD default, so\n   nothing is inferred;\n - each selected branch is deleted only if its tip is reachable from\n   that commit, in place of the usual upstream-or-HEAD check;\n - a branch checked out in any worktree is still refused, and\n   branch.<name>.deleteMerged=false would be honoured;\n - --upstream-gone and the existing --forked narrow the selection, so\n   it doesn't sweep up master or a branch that hasn't been pushed yet.\n\n\"git branch -d --merged=...\" is rejected with the usage message today,\nso this adds a form rather than changing one, and --delete-merged stays\nexactly as it is. In the RFC I worried that this would make -d a second\nbulk-delete mode, but given your point about composability I now think\nthat's the better trade. It avoids both an option that only means\nsomething next to another option and sub-values packed into one\nargument, which I hope answers both of your concerns. I'd welcome being\ntold otherwise.\n\nSo, updating my two questions:\n\n 1. Is \"selection is not proof\" an acceptable basis for deleting\n    gone-upstream branches at all, when the proof is a commit the user\n    names explicitly?\n\n 2. Ben, Harald: is a filtered -d, with an explicit --merged as the\n    proof, the shape you'd want? If so, I'd start with --upstream-gone\n    as a listing filter on its own, since it's useful without the\n    delete half (it replaces grepping \"git branch -vv\" for \": gone]\"),\n    and follow with the -d part as a second patch.\n\nThanks again,\n\n~ Don\n\n"},{"id":"556182","messageId":"CAHwyqnU5abc_KL-R__7G=PU8hGAaRGrXwZLuCkMJE0qoEFfKUQ@mail.gmail.com","threadId":"66562","inReplyTo":"ba149000e13634ffcc5dc51e4d584a56@donquinleone.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-24T18:23:48Z","receivedAt":"2026-10-24T18:23:48Z","isPatch":false,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> D. Ben Knoble wrote:\n> > In this case, if \"topic@{upstream}\" was \"origin/master\", though,\n> > \"--delete-merged=origin/*\" would work, no?\n>\n> Yes. With push.default=current, \"git switch -c topic origin/master\"\n> and a plain \"git push origin topic\", the dry run offers to delete topic\n> once the pull request is merged, with no code change at all. So the gap\n> is only for people who follow the hosting services' advice and run\n> \"git push -u\", which points @{upstream} at the topic's own remote\n> branch. That's the setup I'd hoped to help, and I suspect it's a common\n> one, but I agree the better long-term fix there is teaching the\n> triangular setup. A document like the one you mentioned would be very\n> welcome.\n\nFWIW, I still regard \"squash merge\" as part of a triangular workflow,\nsince GitHub's PRs are inherently triangular.\n\n\nHarald\n\n"},{"id":"556568","messageId":"CALnO6CC+3shDYzX3ks0wk4YuxbsdCCTbKdgHO3fEwHEkN0yx7w@mail.gmail.com","threadId":"66562","inReplyTo":"ba149000e13634ffcc5dc51e4d584a56@donquinleone.com","subject":"Re: [RFC] branch: delete gone-upstream branches only when proven merged into a named ref","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-27T19:34:04Z","receivedAt":"2026-10-27T19:34:04Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"[Liberally trimming some LLM-ish prose?]\n\nOn Sat, Oct 24, 2026 at 12:01 PM DonQuinleone <don@donquinleone.com> wrote:\n>\n> Hi Ben, Harald,\n>\n> Thanks both, this has been really helpful. I've tried each suggestion\n> against the reproduction script with Git 2.56.0, and here's where I've\n> got to.\n>\n> D. Ben Knoble wrote:\n> > In this case, if \"topic@{upstream}\" was \"origin/master\", though,\n> > \"--delete-merged=origin/*\" would work, no?\n>\n> Yes. With push.default=current, \"git switch -c topic origin/master\"\n> and \"git push origin topic\", the dry run offers to delete topic\n> once the pull request is merged. So the gap\n> is only for people who follow the hosting services' advice and run\n> \"git push -u\". That's the setup I'd hoped to help, and I suspect it's a common\n> one, but I agree the better long-term fix there is teaching the\n> triangular setup. A document like the one you mentioned would be very\n> welcome.\n\nYeah… I'm not too sure about the \"push -u\" setup, which only really\nworks when you push to/pull from the same place. I personally want to\nspend my effort weaning folks off that model for triangular workflows\n;)\n\n> D. Ben Knoble wrote:\n> > Rereading our docs for git-branch(1), I think what this RFC is\n> > looking for is\n> >\n> >     git branch --list --merged=origin/main | xargs git branch -d\n>\n> That was my hope too, but it doesn't quite get there in the\n> reproduction:\n>\n>    $ git branch --list --merged=origin/master | xargs git branch -d\n>    error: branch '*' not found\n>    error: cannot delete branch 'master' used by worktree at '...'\n>    error: the branch 'topic' is not fully merged\n\nYeah, I missed that the default output format \"git branch --list\"\ndoesn't course-correct for being machine readable. But!\n\nWe can do\n\n    git branch --list --format='%(refname:lstrip=2)' [filters] | xargs …\n\npretty easily!\n\n> \"git branch -d\" checks topic\n> against its upstream, which is gone, so it falls back to HEAD, and\n> master is behind origin/master. Only\n> -D [works], and that drops the check altogether.\n\nOh, that's interesting, I didn't know that about the deletion checks.\nStill, one can easily dry-run (no xargs) and then -D if needed, I\nsuppose?\n\nNot the best overall experience, but fairly composable, and something\nthat could be built in to Git over time perhaps? idk.\n\n> (The listing also\n> picks up master itself, and would pick up any branch that has been\n> created but not yet committed to.)\n\nAh, yeah. That's a bummer, and the only things I can think of are to\nexplicitly omit it:\n\n    | grep -v \"^$(git branch --show-current)\\$\" | xargs …\n\nor to simply \"let it go\" (even with -D Git refuses to delete the\ncurrently checked out branch). But that's a bit noisy.\n\n> To me that points to the shape you sketched for (B), with one change:\n> when -d is given list filters, the --merged commit is the proof as well\n> as a filter.\n\nAt that point, I would lean towards teaching \"-d\" the same filters as\nthe rest of \"git branch --list\" (and possibly additional ones, like\n--upstream-gone, if needed). That might involve some patches to make\nthe filtering logic shareable between the 2, teaching \"-d\" about them,\nand then extending the set of filters?\n\nJust a thought.\n\n-- \nD. Ben Knoble\n\n"}]}