Bloom Interactive

Bloom Interactive

← Back to home
Preview of Worktree Branch SwitcherView on GitHub ↗

Worktree Branch Switcher


Problem

Git won't let you checkout a branch that's already open in a worktree:

fatal: 'feat/my-branch' is already checked out at '/Users/dan/work/admin.worktrees/feat/my-branch'

The path is right there in the error — but worktree paths are hard to remember. Branch names are easy (GitHub PR, Linear ticket). So why not just use the error to navigate?

Solution

Try to checkout the branch. If it's already in a worktree, catch the error and cd there automatically.

switch feat/my-branch
# Already in worktree, switching to: /Users/dan/work/admin.worktrees/feat/my-branch

Customize the two hardcoded values in the gist for your repo path and default branch.