Using Git Worktrees

Git worktrees let you check out multiple branches simultaneously in different directories. Instead of constantly switching branches and stashing changes, you can work on multiple features, bug fixes, or experiments at the same time, each in its own isolated directory.

Why Use Worktrees?

Creating a Worktree

Let’s say you’re working on a feature but need to quickly fix a bug on main:

# Create a new worktree for the bugfix
> git worktree add ../project-bugfix main

# This creates a new directory with main checked out
> cd ../project-bugfix
> git checkout -b bugfix/urgent-fix
# Make your changes and commit

Listing Your Worktrees

You can see all your active worktrees and which branches they have checked out:

> git worktree list
/Users/dev/project        a1d2422 [feature/new-api]
/Users/dev/project-bugfix b3e4567 [bugfix/urgent-fix]
/Users/dev/project-review c5f6789 [main]

Removing a Worktree

Once you’re done with a worktree, clean it up:

# Remove the directory first
> rm -rf ../project-bugfix

# Then prune the worktree from git's tracking
> git worktree prune

# Or use the remove command to do both
> git worktree remove ../project-bugfix

Quick Tips

Read more about it here