Article View: linux.kernel.git
Article #858switch/checkout stops halfway when it fails to write tracking config
From: 井上司
Date: Tue, 20 Oct 2026 01:39
Date: Tue, 20 Oct 2026 01:39
59 lines
13032 bytes
13032 bytes
1. What happened When writing the tracking config fails (e.g. .git/config.lock exists) while switch or checkout creates a new branch, the command exits with code 1 in the middle of the switch. The worktree and index are already updated for the new branch, but HEAD still points to the old branch. The user then sees unrelated staged changes. 2. Reproduction git init -q -b main up cd up echo one >file && git add file && git commit -q -m one git branch feat cd .. git clone -q up work cd up git switch -q feat echo two >>file && git commit -q -a -m two cd ../work git fetch -q touch .git/config.lock git switch feat; echo "exit=$?" git symbolic-ref HEAD git status --short Output (git 2.43.0): error: could not lock config file .git/config: File exists error: unable to write upstream branch configuration hint: hint: After fixing the error cause you may try to fix up hint: the remote tracking information by invoking: hint: git branch --set-upstream-to=origin/refs/heads/feat exit=1 refs/heads/main M file 3. Expectation I expected it to either complete the switch, or fail without changing anything. 4. Scope The reproduction above uses DWIM (git switch feat). The same happens with switch -c, checkout -b, and --track. With -C on another existing branch, that branch is reset before the failure, so its old commits can only be found in the reflog. 5. Root cause update_refs_for_switch() -> create_branch() -> setup_tracking() fails to write the config, and the code calls exit(1) in setup_tracking() (branch.c). At that point the worktree and the branch have been changed, but HEAD has not. This exit was introduced in 27852b2c53 (branch: report errors in tracking branch setup, 2016-02-22). 6. Related The wrong hint printed for the same failure is fixed separately in <lore URL>. That patch does not fix this problem. 7. Next steps I would like to work on a fix. Should checkout finish the switch and only report the tracking error, or should it fail before touching the worktree?
Technical Details
Message-ID:
<CAP8tz2JPXzq=Skokn4OtH8t6c3b+p1Wny1iX6AhXReUGvsBhuw@mail.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-72477-linux-kernel-git=dewy.ruShow 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-72477-linux-kernel-git=dewy.ru
From: inoue.tsukasa.4@gmail.com (井上司)
Newsgroups: linux.kernel.git
Subject: switch/checkout stops halfway when it fails to write tracking config
Date: Tue, 20 Oct 2026 10:39:14 +0900
Organization: Usenet Network
Message-ID: <CAP8tz2JPXzq=Skokn4OtH8t6c3b+p1Wny1iX6AhXReUGvsBhuw@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: usenet.network;
logging-data="3759283"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:acYC5x3tn6CWdbs76meG89PZsJQ= sha256:Rzn3Yjd5aHDn1FsV5i7d4tvK6kQnmeYzV2r5ZZY5oK0=
sha1:8yJ93SR+uGrFTmZLCujTszEQgvU= sha256:ACqMtbdjOt0q7wIjAwO8I+f2b1V+JcU1wCWrSqLCr+A=
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 84DFF110BAD; Tue, 20 Oct 2026 04:41:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, 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] 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 z47Gs_fOP98q;
Tue, 20 Oct 2026 04:41:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72477-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id CEEDB110AF9; Tue, 20 Oct 2026 04:41:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 2141C61386; Tue, 20 Oct 2026 01:39:52 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792460368;
b=ykn4F4EQRqFF1aGs2FgNsOFsCftcx/H1KgJbPaJKhGvMrkyFisUpyVqH+kYtQZvDr5cw
t/F0OUBQBO+za3U4UMNkm38Zce4nk+pzVCGFNDrG7yAl+vXXnah5pOfWLcPSUwslSzLp3
Ycg7YRCkX8AmOPDcJsMJFj6hGKrFFakluYvJQ5HvCCAC9iBfwo8pt3rUO5ptdmKKVOkWh
q6h1mtu+r/ohOt+mOqIr/Vmvh9jP2hWn5IwPu2eXjUumLS73sS7nD+aUJhMRM1IoZwUa8
/0iFiOFra+4IZ6deJ4C3+1crCkGg56GSVSoV9/i5/tVqpXFfGjCJ6IXcIkyQuc43TVg==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792460368;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:From:Date:
X-Gm-Features:Message-ID:Subject:To:Content-Type;
bh=6g7yqwmlHR8AOtetDXE73nRfr0ocmV6DOXEFGxScss0=;
b=HtXmts7wcIU4s0AmrgKolMltFPKnRiPmtRymnpHesqbxGN6J8LrUjGBqaW93n0RCmQA7
kYxaoG1X3HIP8qUEn/vh6i2tEzABCMNr1DzEaSUeq1x0nr2dxtH5E59cErDj+d96zcC2A
OdBuQYmEMAXabpgO2nRWC9rGt718gSM//GLDXRRFji5NAItjz2MGsaCpQnFmo9ufPuWLl
XVZDts/kUA5ITV5tcXk+bRFkf8Bd33mEkFekoSgaqGeMK+eoN1Fydm+jJCp8ZDgwVESkF
iUTcNhFATksiaAwPTMBa1h/wn4b64jlrhTAP8Wol9psC1uoA+BelIRArbCeLdl8rOPw==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=eePOV9MY;
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 03BEA60A2604;
Tue, 20 Oct 2026 01:39:28 +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=20251104 header.b=eePOV9MY
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.219.49
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792460367;
b=1UdLWr1zkLV90IMc5p4e5F0482ZBWR4DgwA8OePlJtA1zUIsNDc1ogwAEbITIFVNVeOM
HluykJC0BkkUIJo5ISOgpE0zFMzPgqoL2Kn9vewMSJUKJVyGkmnjR7nk8SEN2aoirQSdA
Hi2hz2xyzdajy4FDkwoaVp9PrDmIXsk/ZlZzRSNXchx8ztQdrh8h62J2CQo/8mnMOk5/U
RVs1n9+i4lHeTgsESWWpwXSkUEQpnOVOspfwAANPLuIemMdT4sl8M33bYSUha8qap3WR/
fTtJ8FuOUD9MGwxPmfa0MAFUzINmaBm1wqMjWSafCgCmRmvxPKCPs5DHXXS75nBnPKA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792460367;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:MIME-Version:From:Date:
X-Gm-Features:Message-ID:Subject:To:Content-Type;
bh=6g7yqwmlHR8AOtetDXE73nRfr0ocmV6DOXEFGxScss0=;
b=Kc6C17rrz7HkVugyvR/EPZptllyDnoz6bUahyiOZqAOzwwep8q3ANht7Rrr3HtKtEb90
EOdAVGsNoYU6jr9T339uVua4tpfnTrLBAJCNfhDS+/8HMIVL2/5UprEE2ZKfUPEUQ/fwo
F+PZUOQu+zBIv3rWcwTq//fv3Ifg5RA+7sFTG3DDmd4/3r3NMEJG+kkIZXxHaF1rA26WW
7DOwGvPnCQrfWC1rUZqHA/TkWn83+4xVjx/QCtWh1cmbHPr1rj2SAKcKhl4c4Qc2QvgUJ
wB3CoPf2HjCK6FHr+a9VXahn/9hwMAi6lpfl2PfINhly+wFCjJTrlXL5HGZrPqTIPrQ==
X-ARC-Authentication-Results: i=2; 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=20251104 header.b=eePOV9MY;
arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.219.49
X-Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49])
(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 CBE52606A31A
for <git@vger.kernel.org>; Tue, 20 Oct 2026 01:39:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CBE52606A31A
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-qv1-f49.google.com with SMTP id 6a1803df08f44-91bd6ddb149so6526086d6.1
for <git@vger.kernel.org>; Mon, 19 Oct 2026 18:39:26 -0700 (PDT)
X-ARC-Seal: i=1; a=rsa-sha256; t=1792460366; cv=none;
d=google.com; s=arc-20260327;
b=l4Dus+epMrbbTOrbAfawY5q3TR59Zifoi6tNxbz5ERSXJ6Hy0LARc+jEe4dgac4HUU
rlhst/DN+mQm9KeTuUVh31Lvd1tRl53bX5CCCm95OCTvgoJ8chab9heJ2PhwvXwZUtXa
J6FQ0zpXgwBUZXAoS6msfXkWwq2e0yhozAIQTkhwtnPMQjgc0EBo4s3v509+F3Y8CowF
zj1yM0TDsKcRl5fN7y379wg37Vyl47t7maZv/XPDQM4B+aE2QJTJBi7V6gVAXEs9LIR7
dMIM3E5yywxUhDwrnfozLthxAyG/Km5rH2zaWrdW1bD3W5ow02cjmFiQPiOQ4apJMvMp
iRFA==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
h=to:subject:message-id:date:from:mime-version:dkim-signature;
bh=6g7yqwmlHR8AOtetDXE73nRfr0ocmV6DOXEFGxScss0=;
fh=AdLvfp5rDLFEqEXBqPWoMWgsTSDK6pd8NZNu0VEubK4=;
b=CtS5vhwKPP719Z1BuuXXbDTnBisqNquAhtUFrw3LRCwWcJieTJRy3z08ZV02kxMykN
clFvAIlcDuQAkXR81jLcOlU+A9OXaa8/Q4qbcikE4PEs+n/Ivzis9wmseBYziuj4vdXU
CA+k2f5zcUcvRbnOh4QFu+ygxoM4REn2ql/EwQqCcFH0+gNqYf427pK65gUqGSqJhqs6
ggI3lNFpyevtZtCQ4/gKxDhEdHkrXgjxJioviHdl/w4CLs2XlX8QdnoRpk5TYWSADJ/N
Z/WCx124dQm48CbNKlccgga0N1B9mopBSk8Rgii02u7CH5RsElBWjyLkaz31Rbnd598I
0KnA==;
darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792460366; x=1793065166; darn=vger.kernel.org;
h=content-type:to:subject:message-id:date:from:mime-version:from:to
:cc:subject:date:message-id:reply-to:content-type;
bh=6g7yqwmlHR8AOtetDXE73nRfr0ocmV6DOXEFGxScss0=;
b=eePOV9MYJlo6YEukgOJdXAQ1/ICMWW7cYFR6S8TiB+MeUx0irvitkIgDDNjpvW5lW9
Vt5aDhMAHC8i2oHfn8tN4FWHEIDA4jgNDQLWeVH58QbAFbLtyMEfa6JLKMaDt/r9Hcus
JiQ4EgjzIu+2LehN+a7iyKXY3nIqiHGkymlWWmXaRNrjjL7SA+gRhQYs0UKBwTOFywYp
eEJBHPz8PBnU/LFVEohIjqHvl7Mkd348bTF9AkkTo850lI3MN5Hw1rE5JVrajCCAUYhT
IVPIClF7BnzL2zIIZok3zl6Llpqj0ZnbfvfSNVqb4PbIO6Oj1Hs/bReUS0NUpCu7nSfO
9nJw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792460366; x=1793065166;
h=content-type:to:subject:message-id:date:from:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=6g7yqwmlHR8AOtetDXE73nRfr0ocmV6DOXEFGxScss0=;
b=Qf6D2le6NeeCTKnvb2Zpaj8pXhAqTiM4lQ0epEwFGBwelaTMaPRV52sBeixl9WR/JH
HqAoBDb79MK1V2WrO9JcIgkjRr/HeHv+w6iRUUhUnlCzxa8U5JrVgmbh562UI8vPx/vl
VD60WIjcMlPo5yG6R/kGUBTpv0gsKunK2oNUXB+2ul5dxsv/pbQgpeTdU4gUNDBwQFvY
FMEDOe5wipJTSS8YTEiDpGFPViSeXzOZ9r5IXeQ8DmnBMu6GrtkOYhKni/J4h/zCpXv8
Wxr5H5xWdx0kIQJR6d+p3d5tMTJez8MOpgB2YH1QEvx5bziqTikGsXIQ6DqcFlvXee+8
FNQA==
X-Gm-Message-State: AFq9FYJPRv7cbDXGYrwCsaAJTfQ8VxYWoQh1U+0OcMJbMEXcXsc3Phf2
rtkwNlSIZMXq6GN4y6pOQxoSH4OiuUdMaZAjU4hsvcuCZsUeChfK/FhZNtSuJOXeEdOfqZbX/De
A/DwV4ZPT4L7U1B17X/tCmBBCcVm7xrO0RyoM
X-Gm-Gg: AYBFou2MDDTHfZb1oERJG7hXfyiv3v13DoBn8iulTEw+txaoAwVnL8iRLwI/gBclwl2
jb9oJkEGlnkISp+tjRqbilcyiVRDEthaOGnmMFtPZ9AjTua0MfQzJE6XS6ZLQ63vPpHGwuXBNOm
HuG6xzLaomCjMvrQHZO6rZcca7dPPaRa8pMqFoYoyZA7cISLCKv8aFf15hChwN50RFNx58Ytwiy
GNDM1nYVsGaaLYjLcCasB9LNjnwJg/L60AMOfigVO0SE3d1RwV1aspKPNumKx4mPpiSx5PJt17K
0CGlSaycPzTnm3kULPDF7HFbUi0ngpiecmgGwGKoLZ3oaWZcZjvGhQ==
X-Received: by 2002:a05:620a:17a2:b0:93f:1a1a:2974 with SMTP id
af79cd13be357-93f29e1748emr1706696385a.6.1792460365713; Mon, 19 Oct 2026
18:39:25 -0700 (PDT)
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-Gm-Features: AclHuK_npVeFd8XE21GoIB-qSuRMK9pBREuBGtuZ_WwNWzyJ0kyqiuwlaNyOIBk