Article View: linux.kernel.git
Article #1914[PATCH v5 0/4] branch: let --delete-merged find squash merged branches
From: "Harald Nordgren via GitGitGadge...
Date: Fri, 30 Oct 2026 10:52
Date: Fri, 30 Oct 2026 10:52
123 lines
16376 bytes
16376 bytes
Branches merged on GitHub with "Squash and merge" or "Rebase and merge" are
never deleted by git branch --delete-merged, because their tips are not
reachable from the upstream. This treats such a branch as merged when some
upstream commit contains all of its changes, and names that commit in the
output:
Deleted branch topic (was 1a2b3c4, landed as 9f8e7d6).
Changes in v5:
* git branch -h lists --delete-integrated in the usage lines
* Giving both --delete-merged and --delete-integrated dies with a short
"cannot be used together" message instead of the full usage text
Changes in v4:
* --delete-merged works as it does on master again: it only deletes
branches whose tip is reachable from their upstream
* New --delete-integrated <pattern> also deletes branches that were rebase
or squash merged, including those squashed after upstream changed the
same files. It replaces --squashed
* New prep commit lets delete_branches() take a map of where each branch
landed, so "landed as" is printed there
* Added Junio's test that --delete-merged keeps a branch when an unrelated
upstream commit adds an identical file
* --dry-run works with either option, and the two options can't be combined
Changes in v3:
* Split into multiple commits, one for rebase merges and one for squash
merges.
* By default a branch counts as merged when an upstream commit has its
exact version of every file it changed. This never reads file contents,
so it stays cheap in a partial clone. It finds rebase merges, and squash
merges where upstream left those files alone.
* Replace --no-squashed with an opt-in --squashed, which also finds
branches merged after upstream changed the same files by merging those
files.
* Add a test for a rebase merge, and check that a squash onto changed files
is kept without --squashed and deleted with it.
Changes in v2:
* Diff each upstream commit once and share the result between all branches,
faster than v1.
* Fix a branch merged with a merge commit being reported as "landed as" the
merge when another branch was searched first, and add a test for it. Show
the topic commit itself in "landed as" for work that arrived through a
merge.
* Use git merge --squash as the example in the commit message and mention
GitHub's squash and rebase buttons.
* Add --no-squashed to skip the squash search.
Harald Nordgren (4):
branch: move the deleteMerged opt-out check into a helper
branch: let delete_branches() name where a branch landed
branch: add --delete-integrated to delete rebase and squash merged
branches
branch: let --delete-integrated find branches merged onto changed
files
Documentation/config/branch.adoc | 8 +-
Documentation/git-branch.adoc | 22 +-
builtin/branch.c | 360 +++++++++++++++++++++++++++++--
t/t3200-branch.sh | 218 +++++++++++++++++++
4 files changed, 578 insertions(+), 30 deletions(-)
base-commit: 8d1b215c01512b9658d4525c54ff9b9245f9a7e8
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2425%2FHaraldNordgren%2Fbranch-delete-squashed-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2425/HaraldNordgren/branch-delete-squashed-v5
Pull-Request: https://github.com/git/git/pull/2425
Range-diff vs v4:
1: 1d01085b75 = 1: 090aec5725 branch: move the deleteMerged opt-out check into a helper
2: 592562d7e7 = 2: 24180bf4a2 branch: let delete_branches() name where a branch landed
3: deb1e649cf ! 3: bf30f57ceb branch: add --delete-integrated to delete rebase and squash merged branches
@@ builtin/branch.c
static const char * const builtin_branch_usage[] = {
N_("git branch [<options>] [-r | -a] [--merged] [--no-merged] [(--forked <branch>)...]"),
+@@ builtin/branch.c: static const char * const builtin_branch_usage[] = {
+ N_("git branch [<options>] [-r | -a] [--format]"),
+ N_("git branch [<options>] (--delete-merged <pattern>)... "
+ "[<branch-pattern>...]"),
++ N_("git branch [<options>] (--delete-integrated <pattern>)... "
++ "[<branch-pattern>...]"),
+ NULL
+ };
+
@@ builtin/branch.c: enum delete_branch_flags {
DELETE_BRANCH_SKIP_UNMERGED = (1 << 2),
DELETE_BRANCH_NO_HEAD_FALLBACK = (1 << 3),
@@ builtin/branch.c: int cmd_branch(int argc,
if (filter.with_commit || filter.no_commit ||
@@ builtin/branch.c: int cmd_branch(int argc,
+ filter.points_at.nr || filter.forked.nr)
+ list = 1;
++ die_for_incompatible_opt2(!!delete_merged.nr, "--delete-merged",
++ !!delete_integrated.nr, "--delete-integrated");
++
noncreate_actions = !!delete + !!rename + !!copy + !!new_upstream +
!!show_current + !!list + !!edit_description +
- !!unset_upstream + !!delete_merged.nr;
@@ t/t3200-branch.sh: test_expect_success '--dry-run without --delete-merged is rej
+test_expect_success '--delete-integrated cannot be combined with --delete-merged' '
+ test_must_fail git -C forked branch --delete-merged origin/next \
-+ --delete-integrated origin/next
++ --delete-integrated origin/next 2>err &&
++ test_grep "cannot be used together" err
+'
+
test_done
4: 19a9630c13 = 4: 9443055242 branch: let --delete-integrated find branches merged onto changed files
--
gitgitgadget
Technical Details
Message-ID:
<pull.2425.v5.git.git.1793357582.gitgitgadget@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73890-linux-kernel-git=dewy.ruReferences:
<pull.2425.git.git.1790667030497.gitgitgadget@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73890-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v5 0/4] branch: let --delete-merged find squash merged branches
Date: Fri, 30 Oct 2026 10:52:58 +0000
Organization: Usenet Network
Message-ID: <pull.2425.v5.git.git.1793357582.gitgitgadget@gmail.com>
References: <pull.2425.git.git.1790667030497.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2218655"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:d8LmAs7q/qOss7VeR1dksbIEQ5s= sha256:RrHNtKcLPTN30GOvVM80bog59sd1BmfiGtsuwXM2QDU=
sha1:GaHySPSExTpPkW2Ek0t62NNj5sM= sha256:ygllJE/B9W9Qh6Cl0mJdzb8BO2dC6hB2Q8pchLxU5kY=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 07532125C92; Fri, 30 Oct 2026 14:09:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.147
X-Spam-Status: No, score=-3.147 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id qSfftkxKSEWU;
Fri, 30 Oct 2026 14:09:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-73890-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 0015E125C8E; Fri, 30 Oct 2026 14:09:22 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id F0024607EEA; Fri, 30 Oct 2026 10:58:06 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793357587;
b=OXDDfYjc+B9w8OKDTyaayVzofH4d3VX8ZGmfHSpTgW0lKQxmhVElIa3CnH4rMOjuIjjS
Yss2ELeYDaTW2IihNjUgGH/ZsFPuHGTtwyr0gkDo2obKByTlTeOhwX3d3h2GVckyxpm0o
On2aMtgA6k5Zu6/VHj6FwRKZOPcnifZiLUDb2BLI26+HX0gIctKopuj139CKIeJrC/tDx
5zbSELdN1rDiJKgig7nZY0WROR9iQDyoQgjxEz+rP5/yGfkZwrZFruPKOL4NmBURh1Vvx
oe47QRhrBQf/wpXJFzGXQ42qME4ZDnI5lTK5hn1AY4tqYePlA9tCC1+wPJ07HxsVRvg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793357587;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-Id:In-Reply-To:References:From:Date:Subject:Fcc:
Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:To:Cc;
bh=XyBH980KXRNeJ2MbT5MwM32P/ZqK8gn3MvoLXOAfC9Q=;
b=u/CiwdPgwaQKnOjWJVMY3lk60M5W1vgwOkM2XIIB3+WVpYYNWCTfUvQFvoGr6P/vndyW
/d7wZtWebDMLNyT0LFGlkftJ7CZqj9DLZyZuK95hVoRjxEWA78e0KMocFP86ngiUbsSfp
X/XE2ZOiPEHAnOuIFeeeRb1RrwjOHlKRfnPyU95GB+Zz/A3lVwM1xtc9GHQPFkt5k3jRg
IOdCxwfMPnvqlwpyXtP9hvqAccKSGpoAm4vZLjjL0WXMNY+kpt0VsG/3+IPMXAyIuY48F
0W1D9l5G7zys78UCte3NU2tyLO2lJaSPQdLKmG7Da71Hm3x56DY0W+i9c4MfUO8I5MA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KN6aBYag;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id B45F760A3817;
Fri, 30 Oct 2026 10:53:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KN6aBYag
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793357586;
b=wUmsPmKE7jWo54AXmWfTceJtSmBHhMA2ebwkJNdldHp0zr1WrKqZKMPxy6Nf2x6TC1ef
TRe7cGueCKh9OpRPkGqvpyjwlTzxBqlqnQFaFIBMnvBenFDFclgw5RTOmQ3NlW6IpgMhd
/QSIOTiub59tBVDsF+ydHyonPzgpq5OGqufkYh3CNXlcIAsObCTBQhyuClkKLd3SOVp0o
sYra+3jLOAJ2+bRXBQWUZD8ZntfORWUCqrGyn+4mLRThJj9bn5Ufs+t5WqEu61t3e7L3R
VcMG7Gqag0YUmV7dPve2cXiEfKpbUBr/mBECa1NGW4Kh/WqyK5LrsO8MZW89rEHMu4Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793357586;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To:
References:From:Date:Subject:Fcc:Content-Type:
Content-Transfer-Encoding:MIME-Version:To:Cc;
bh=XyBH980KXRNeJ2MbT5MwM32P/ZqK8gn3MvoLXOAfC9Q=;
b=N7o/BXgTR+FtuXy/I7FARTC94mlU1/NC4LM6l51kgdJj9qkJ2EXBH483nGcxotX4shC3
/KihlPITmK/dR+QQB6w9RQ0p3xeyRlf7uQJCdGxbcsbRbJtrTRetSOZvbPgv5pawn68//
0tg2+/JS/hmGLiIVNtl5I0WMKx0BtlJ1EzuwgaPfXLTzb5LW5jlDZh8Uv9keXoZqXMxBf
zRIZcyROdettlO1t0zVCb3k5ey4jRmb51cyrlDvbhF0EACvgngX0eIOeBfIgyse7RuoFN
MjTPszM+fw+fAuyGsIdQNzkA9lNk7oLpRcbfnbAR1TW4b29T827Ys1K6Q8/3Z0eM7Lg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KN6aBYag;
arc=none smtp.remote-ip=209.85.160.47
X-Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8350460706B3
for <git@vger.kernel.org>; Fri, 30 Oct 2026 10:53:06 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8350460706B3
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-451a49abd8aso566630fac.3
for <git@vger.kernel.org>; Fri, 30 Oct 2026 03:53:06 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793357585; x=1793962385; darn=vger.kernel.org;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:references:in-reply-to:message-id:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=XyBH980KXRNeJ2MbT5MwM32P/ZqK8gn3MvoLXOAfC9Q=;
b=KN6aBYag8wem/WgcR2eia9KYVYp8bBQ6c9L0KUdDUSh1p08VlY7cafmd1r2tiT4Khz
zyRlTLa2Nq57F0DtH9oxNHxvbHiZW1poHx5bqllVsoJ5Y/9gDjsbO37yBUnfSZh0b3Si
jgnvrKYbefqYiEyN6UmEPoAK9I7H4Bg9KokOsvnzItYLXJovnZM5qAANyC/8Uw1eTxso
EKds2hdv974mWPmuOqbbxUHAynHsqbuj6zijNdKO5wbL9ykny07ywV0CNG57/qNtznwv
cNv8oUuZFUr3xn/yPVDnA3vNswj2/lA02695XczLSNuwAoKnUZnFw3RWOjbhVxr7vUVb
fDmA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793357585; x=1793962385;
h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
:subject:date:from:references:in-reply-to:message-id:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=XyBH980KXRNeJ2MbT5MwM32P/ZqK8gn3MvoLXOAfC9Q=;
b=Oia9Y2UwRCcFeeQvRcbWxUMm2rOAp73AFFjjv2r8mwLbj3UMgDXtdgFBqsGBYkMJ6m
/peBzCRVQHnDwpCeEl/JaYyaqEkQxGN1itTcjt9Ollz3F4apLf7iMQ+fHS8vjzNCwR4G
C1Zzq/3zyn/idD45gX0TBKXpODNBN7n59WkZNnlNYZKluFuQrhPE8/e1k9Xb0s471KN2
/5ChWtW+iO9kp1pGY3taFl3FIvzpH4tLE9HpUE5F+Il8NiUGcP0PEv5tcO00f7Hm5xXH
fLb+a/LWNlfMY0UANOdKhH093gfewyz/ZDPWx/hJA1+sdfRKDgictnUslZ/DSJ0DwvKs
JMvA==
X-Gm-Message-State: AFq9FYIG+AxMU+QDHQKif2OnVdRakiroPu0pl1xa0tvIaI3iBpZzM5Xd
OYQp0ApoCHmeO2YQ8E2EZy9WkQX/RujejRruC35W4ScNksPvM/U0yEMPI6Sul7xX1/w=
X-Gm-Gg: AYBFou2Q0Lb+YHFdmMaB1xnYe9j6k87c19I8aa9YlWHPMJOCOxCbbP5Bt1mxfODzBNa
PPALhNLuNJuwgbqezCFJUo36T2iVQ9r0v2Dw94JlQuBK2+E5HEiGiMEbxcaAyxWvhHAIWUXV2sP
D0uL7qjsgJvTM4MSDEV+HagkEv9wofnEY9Ku25ePaKhNYobKb6BLbX/9HsosJUCVT4MKt1DRLDV
UjiqNtT5dbTf9tANgHY61MubeARTgomWPPGQMV6bhQ4v2sVQQf2xndN1wQ8bWRM4TF6f3TiI5y4
g2kXiZdEBmqkt6LZdYxRqRjM6t9+6zByfwGNaOXhTpwdcaDlnz9K/K6hNHo3PDMMa5im1BBmrNy
16wWfGj0bMKMfSar0QvuDg8ccBFIhI3PI4VVPxwA7Rwsw9z6TKTNePkmm8Ae/SDn+w51zYJhWmJ
NAnC+KxZUCXfG0MKl1xUHajXK2OcR746difTA9GW4qO+sk7prnWYlKl+u3KX6jKERb8h4soStlz
d5tKHzHaFqwXI5AVyqcJM69RTl5kS9t66n+TiQPDR2126dz/ByRSYagJlIn44x9QWbUAmGVPZiN
Jc5SqngEfwr9kO1YdoBzUWOIgynrtCQj5lhgZ1nQY479zdJG1by/Ni0=
X-Received: by 2002:a05:6871:4b0b:b0:47d:f10:686f with SMTP id 586e51a60fabf-4a9076b74efmr1165067fac.23.1793357585453;
Fri, 30 Oct 2026 03:53:05 -0700 (PDT)
X-Received: from [127.0.0.1] ([132.196.62.244])
by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4a90ae4dd00sm1500623fac.5.2026.10.30.03.53.03
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 30 Oct 2026 03:53:04 -0700 (PDT)
X-In-Reply-To: <pull.2425.git.git.1790667030497.gitgitgadget@gmail.com>
X-Fcc: Sent
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-Cc: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
"D. Ben Knoble" <ben.knoble@gmail.com>,
Phillip Wood <phillip.wood123@gmail.com>,
Jasper Mayone <me@jaspermayone.com>,
Harald Nordgren <haraldnordgren@gmail.com>