Jacob Wiseberg

← back

Rethinking My Git Workflow With Worktrees

For years my answer to “I need to look at another branch quickly” was git stash, switch, look, switch back, git stash pop, and hope nothing conflicted. Worktrees finally broke that habit.

The problem I’d been living with

Agent-driven coding made the stash dance actively painful. I’d have an AI coding session running in one branch, want to quickly check something on main, and either interrupt the session or open a second clone of the repo just to avoid touching the first one’s working directory. Second clones work but waste disk space and drift out of sync with remotes in annoying ways.

What a worktree actually is

A worktree is a second working directory attached to the same repository, checked out to a different branch, sharing the same .git history and objects:

git worktree add ../myrepo-feature-x feature-x

That creates a sibling directory with feature-x checked out, fully independent of whatever’s happening in the main directory. Same repo, same remotes, same reflog, zero duplication of the object database.

How I actually use it now

My pattern settled into one worktree per active line of work:

git worktree add ../myrepo-review main        # for quick lookups on main
git worktree add ../myrepo-hotfix hotfix/bug  # for an urgent fix
git worktree list                             # see everything checked out

When an agent session is mid-task in one worktree, I can cd into another, make an unrelated change, commit it, and come back without either session ever noticing the other existed. No stashing, no “wait, what branch am I on” moments.

Cleanup is just as direct:

git worktree remove ../myrepo-hotfix

It refuses to remove a worktree with uncommitted changes unless you force it, which has saved me at least once from losing work I’d forgotten about.

The gotcha that took me a minute to understand

You can’t check out the same branch in two worktrees at once. Git will refuse, which makes sense once you think about it: two working directories both claiming to be the authoritative state of one branch would be a recipe for silent data loss. The error message is clear once you’ve seen it, but the first time it happened I spent a few minutes confused before realizing I’d already checked that branch out elsewhere.

Where this landed

I don’t reach for a second full clone anymore, and the stash dance is basically gone from my daily workflow. The mental model that clicked for me: branches are cheap, but your working directory is the scarce resource when you’re juggling multiple things at once. Worktrees let you have as many working directories as you need without paying for extra copies of the whole repository’s history. It’s the kind of feature that was always there and I just never had a good enough reason to learn until juggling parallel work actually hurt.