`gco`: Your Brain Shouldn't Track What Git Already Knows
Amy Sillman, Split
Summary
Worktrees split your work across directories, and after enough context switches you stop keeping track of which is which. So I wrote eleven lines of shell to stop tracking it.
I hit fatal: 'fix/my-branch' is already used by worktree at '/path/to/worktree' about four times a day. I know exactly what it means and exactly where to go. I keep typing git checkout anyway.
I've been using git worktrees heavily since switching to agentic coding with Claude. A worktree lets you check out a branch into a separate directory without cloning the repo again: same git history, isolated working tree. Each branch Claude works on gets its own directory, no stomping on active work. The branches I'm touching myself get regular checkout.
Split workflows create mental state. After enough context switches, you stop carrying it.
The fix is eleven lines of shell. Add it to your .zshrc or .bashrc. gco is a drop-in for git checkout. It wraps git checkout, lets it run, and if it fails with a worktree conflict, pulls the path straight out of git's error message and cds you there.
worktree_path=$(echo "$output" | sed -n "s/.*worktree at '\([^']*\)'.*/\1/p")
Git already put the path you need in the error text, so there's nothing to track by hand. Attempt the checkout, catch the specific failure, recover. If it succeeds, it passes straight through. Anything other than a worktree conflict surfaces the original error untouched.