# Fix worktree→local branch switch causing 'already used by worktree' error · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/commit/d6ecf1580510cd7f156dbe831c68f357fe162210)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

Requested revision: d6ecf1580510cd7f156dbe831c68f357fe162210

Requested commit: d6ecf1580510cd7f156dbe831c68f357fe162210

Commit: d6ecf1580510cd7f156dbe831c68f357fe162210

Tree: c6c1e9f3569cd1fa7bd9e2ecc91dd3d2b7d55b4b

Author: Julius Marminge

Committer: Julius Marminge

## Message

```
Fix worktree→local branch switch causing 'already used by worktree' error

When in a secondary worktree and selecting a branch checked out in the
main worktree (e.g. main), the code skipped the worktree redirect
(because worktreePath === project.cwd) and tried git checkout, which
git rejected.

Now any branch with a worktreePath is handled as a redirect — main
worktree redirects to local (worktreePath=null), secondary worktrees
redirect to their path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

```

## Parents

- [5b7af7b9f641b8e8f1bdffabcdd423d3f09e9d80](https://git.cafe/pingdotgg/t3code/commit/5b7af7b9f641b8e8f1bdffabcdd423d3f09e9d80?format=markdown)

[Source at this commit](https://git.cafe/pingdotgg/t3code/tree/d6ecf1580510cd7f156dbe831c68f357fe162210?format=markdown)
