4 min read
Stop Stashing and Start Using Git Worktrees
Stop Stashing and Start Using Git Worktrees

If you’ve ever found yourself mid-feature, deep in a flow state, only to have someone ping you with “Can you hotfix this real quick?” — you know the pain. You stash your work, switch branches, fix the thing, switch back, pop the stash, and pray nothing got weird.

There’s a better way. It’s called git worktrees, and once you start using them, you’ll wonder why you ever lived without them.

What’s a Worktree?

A worktree lets you check out multiple branches of the same repo in different folders — simultaneously. No stashing. No switching. Just cd to another directory.

Think of it this way: your repo’s .git folder is the brain, and worktrees are just different bodies it can inhabit at the same time.

/Projects
  /my-app              ← main branch lives here
  /my-app--feature-x   ← feature branch lives here
  /my-app--hotfix      ← hotfix branch lives here

Three terminals. Three branches. Zero context switching.


Quick Start

Create a Worktree

From inside your main repo:

# For an existing branch
git worktree add ../my-app--feature-x feature-x

# For a new branch (branching off main)
git worktree add -b hotfix-123 ../my-app--hotfix main

Pattern: git worktree add <path> <branch>

That’s it. You now have a fully functional checkout at that path.

List Your Worktrees

git worktree list
/Projects/my-app              abc1234 [main]
/Projects/my-app--feature-x   def5678 [feature-x]
/Projects/my-app--hotfix      ghi9012 [hotfix-123]

Remove a Worktree

When you’re done with a branch:

git worktree remove ../my-app--hotfix

Or if you already deleted the folder manually:

git worktree prune

Real-World Workflow

Here’s what this looks like in practice:

# You're heads-down on a feature
cd /Projects/my-app--feature-x
# coding, vibing, in the zone...

# Slack: "URGENT: prod is broken, need a fix NOW"

# Old you: stash, switch, panic, forget what you stashed
# New you:
cd ../my-app
git worktree add -b hotfix-prod ../my-app--hotfix main

cd ../my-app--hotfix
# fix the bug
git commit -am "fix: resolve prod issue"
git push origin hotfix-prod
# open PR, get it merged

# Clean up
cd ..
git worktree remove my-app--hotfix

# Back to your feature like nothing happened
cd my-app--feature-x

Your feature branch is exactly how you left it. No stash conflicts. No “wait, what was I doing?” moments.


Tips & Best Practices

Use a Naming Convention

Keep your sanity with consistent naming:

/Projects
  /my-app                    ← main checkout
  /my-app--feature-auth      ← feature branch
  /my-app--bugfix-123        ← bugfix branch
  /my-app--experiment-foo    ← throwaway experiment

The -- separator makes it instantly clear what’s a worktree of what.

Worktrees Can Live Anywhere

They don’t need to be siblings. This works fine:

git worktree add ~/scratch/quick-test some-branch

Put them wherever makes sense for your workflow.

Keep Your Main Checkout Clean

Some developers use a bare repo as the “brain” and only use worktrees:

git clone --bare git@github.com:user/repo.git my-app.git
cd my-app.git
git worktree add ../my-app main
git worktree add ../my-app--feature feature

This is optional but keeps things tidy if you’re a worktree power user.


The One Rule

You cannot have the same branch checked out in multiple worktrees. Git enforces this to prevent you from creating merge nightmares.

If you try, you’ll get:

fatal: 'main' is already checked out at '/Projects/my-app'

Just create a new branch if you need parallel work.


TL;DR

TaskCommand
Create worktree (existing branch)git worktree add <path> <branch>
Create worktree (new branch)git worktree add -b <new-branch> <path> <base>
List worktreesgit worktree list
Remove worktreegit worktree remove <path>
Clean up deleted foldersgit worktree prune

Start Today

Next time you need to switch contexts, don’t stash. Create a worktree. It takes 5 seconds and saves you from the cognitive overhead of branch juggling.

Your future self — the one who gets interrupted constantly — will thank you.