Skip to content

fix(shell): go to the worktree holding a branch instead of taking it - #55

Merged
potsrevennil merged 1 commit into
mainfrom
fix/checkout-go-to-holder
Oct 21, 2026
Merged

potsrevennil merged 1 commit into
mainfrom
fix/checkout-go-to-holder

Conversation

@potsrevennil

Copy link
Copy Markdown
Owner

git checkout <branch> (and gco/gsw) switched the main checkout to the branch even when another worktree had it checked out, detaching that worktree to free it. A branch open in a worktree usually means someone, often a Claude session, is working there. So this moved checkouts out from under people: in practice, a branch you meant to visit ended up in the main repo, with its worktree left detached.

Now a branch held by another worktree takes you into that worktree, and nothing is detached. Free branches still switch the main checkout, and the current worktree's own branch still stays put. -. ("this worktree") is still the explicit way to take a branch from another worktree, as before: only when that worktree has no uncommitted changes to tracked files, and reattached if the switch fails.

  • Look at: the new early return in _git_switch_in. It reads the caller's here (set by -. in git()) through zsh's dynamic scoping, like wt and top.
  • Verify: a scratch-repo script covering 23 cases passes: held branch (cd only), -. take with clean, untracked-only and dirty holders, reattach after a failed switch, PRs with and without -., plus the earlier free-branch, remote-only, PR and passthrough cases.
  • Out of scope: the git worktree path helper and the PR resolution logic are unchanged.

🤖 Generated with Claude Code

`git checkout <branch>` switched the main checkout to a branch even when
another worktree had it checked out, detaching that worktree. A branch
open in a worktree usually means work is happening there, so this moved
people's checkouts out from under them. Now it cds into that worktree
and detaches nothing; free branches still switch the main checkout.
`-.` (this worktree) remains the explicit way to take a branch, still
only from a worktree with no uncommitted changes to tracked files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@potsrevennil
potsrevennil marked this pull request as ready for review October 21, 2026 05:35
@potsrevennil
potsrevennil merged commit 212ce56 into main Oct 21, 2026
7 checks passed
@potsrevennil
potsrevennil deleted the fix/checkout-go-to-holder branch October 21, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant