How to Use Git Worktrees Effectively and Why It Is Crazy Powerful
TLDR: Git worktrees allow you to have multiple working copies of the same repository checked out at the same time, each on a different branch. Instead of stashing changes or committing half-finished work to switch branches, you just open another directory. Once you start using them, you will wonder how you ever worked without them.
[Anders' take — coming soon]
Most developers have felt the pain: you are deep in a feature branch, someone asks you to review a PR, and now you need to stash everything, switch branches, do the review, switch back, and pop the stash. Half the time something goes wrong with the stash, or you forget where you were. Git worktrees eliminate this problem entirely.
A git worktree is a linked working copy of your repository. It shares the same .git directory, the same history, the same remotes — but it lives in its own folder with its own checked-out branch. You can have as many worktrees as you want, and they are cheap to create and destroy.
Here is how to get started:
- Run git worktree add ../my-feature feature-branch to create a new worktree
- Each worktree is just a regular directory — open it in your editor, run tests, do whatever you need
- When you are done, run git worktree remove ../my-feature to clean up
- Use git worktree list to see all your active worktrees
The real power shows up in three scenarios. First, parallel development: you can work on a feature in one worktree while a long-running test suite executes in another. Second, code reviews: check out the PR branch in a separate worktree and review it without touching your current work. Third, AI-assisted coding: tools like Claude Code can operate in an isolated worktree, making changes without interfering with your main workspace.
The mental model shift is important. Stop thinking of your repository as a single directory with one active branch. Think of it as a database of code that you can project into as many directories as you need. Each projection is independent, but they all share the same underlying history.
Common pitfalls to avoid:
- Do not check out the same branch in two worktrees — git prevents this for good reason
- Remember that worktrees share the same stash, so be careful with git stash commands
- If you delete a worktree directory manually, run git worktree prune to clean up stale references
For teams using CI/CD pipelines, worktrees can also speed up build processes by allowing parallel builds of different branches on the same machine without full clones.
The combination of git worktrees with modern AI coding assistants is particularly powerful. You can have your main work in one worktree, let an AI agent work on a task in another, and merge the results when both are ready. This is not theoretical — it is how many teams are working right now, and it is a genuine force multiplier.