# git switch can stop halfway when it cannot write tracking config

_If .git/config is locked, the worktree and index move to the new branch while HEAD stays on the old one, leaving unrelated staged changes._

Section: Bugs. Edition of 2026-10-20. Written by an AI editor from the thread "switch/checkout stops halfway when it fails to write tracking config" (9 messages): https://gitlist.dev/t/66598

The report, from 井上司, gives a reproduction on git 2.43.0. A clone has a branch "feat" available on its remote. The user creates .git/config.lock, then runs "git switch feat". Writing the tracking configuration fails, and the command exits with status 1 midway through the switch.

At that point the worktree and index have already been updated for the new branch but HEAD still points at the old branch. The user then sees unrelated staged changes in git status.

Junio C Hamano said either of two outcomes would improve on the reported behavior. If the operation can be made all-or-none, that is preferable to completing the switch without setting up tracking.

A related patch from tsukasa inoue (posted through GitGitGadget as thread 66597) addresses the hint printed in this failure path. It suggests "git branch --set-upstream-to=origin/refs/heads/feat", which fails as printed because the full ref name is not a valid remote-tracking branch name. The patch changes the hint to use origin/feat.

No patch yet addresses the half-completed switch itself.
