From: Phillip Wood Date: Mon, 22 Jun 2026 09:25:47 GMT Subject: Re: [PATCH v14 4/6] branch: add --prune-merged Message-ID: <64ea35df-bdc9-42bd-ac16-5719c5bc6953@gmail.com> In-Reply-To: Hi Harald On 20/06/2026 10:04, Harald Nordgren wrote: >> - Move the @{upstream} of feature2 to the branch that "merged" >> feature1 and caused its removal. Asking feature2@{upstream} >> would answer origin/master, which feature1 was removed after >> getting merged. > > I think this is a strong option. > > As a side note: I was annoyed before when GitHub didn't re-assign base > automatically when doing stacked PR's, so merging in the first branch > caused developers to merge in the second PR into essentially a dead > feature branch instead of master, if they forgot to manually change > it. But I think GitHub has fixed this now so the second PR gets its > base changed to default branch. > > Two caveats: > > - How to handle recursion: b1 has b2 as upstream and b2 has b3 as > upstream, and both b2 and b3 have been merged? Not good if it's just > luck which order the branches get walked, but also we don't want to > have to do many passes, two passes is not even guaranteed to be > enough. I think you only need one pass. For each branch we look at it's upstream and if it is in the set of branches we want to delete we 1 remove it from the set of branches to be deleted 2 if the upstream of the upstream is in the set of branches to be deleted goto 1. Note that we don't need to create a list of all upstream branches, we can handle it within the refs_for_each_branch_ref() callback. > - What about when b3 has itself as upstream? I guess then we can just > remove the upstream of b2. Overall, I don't think it's a huge problem > when a branch gets no upstream, so maybe just warn about it. Removing the upstream config of branches that are merged shouldn't cause too many problems - the user is unlikely to want to rebase a merged branch and they're unlikely to have it checked out so "git rebase" and "git log @{u}.." probably does not matter. So maybe we should change the loop above to only keep the upstream branch of branches that have not been merged and instead clear the upstream config of any merged branches we keep because they are an upstream of another branch. Thanks Phillip