Git Worktrees Are Having a Moment — And for Good Reason
If you've been spending any time in developer communities lately, you've probably noticed that git worktrees are generating a lot of buzz. That's a little ironic, considering they've been part of git since 2015. But better late than never — because worktrees are genuinely one of the most underrated tools in a developer's daily workflow, and once you start using them, it's hard to imagine going back.
In this article, we'll break down what git worktrees actually are, why the traditional approach to context switching is so painful, and how worktrees solve that problem more elegantly than you might expect.
The Problem: Context Switching in a Worktree-Less World
To appreciate why git worktrees matter, you first need to feel the pain they eliminate. Picture this: you're deep in the middle of building a new feature — let's say a login system. You've got half-written code everywhere, files open, and your brain fully loaded with context. Then a Slack message arrives. There's an urgent production bug, and you need to drop everything and fix it now.
In a world without worktrees, you have a few options, and none of them are particularly great.
Option 1: Stash Your Work
The most common approach is to stash your current changes using git stash. You'd run something like:
git stash "wip feature login"
This tucks away your uncommitted changes so you can switch branches cleanly. Then you check out the branch you need, fix the bug, commit, push, and finally pop your stash to resume where you left off. It works — technically. But it's clunky. Stashes are easy to forget about, they can conflict when you pop them, and the whole process interrupts your mental flow in a jarring way.
Option 2: Commit Half-Finished Work
Another option is to just commit your work-in-progress with a message like "WIP — do not merge" and switch branches that way. This pollutes your commit history, creates confusion in pull requests, and requires cleanup later. It's a workaround, not a solution.
Option 3: Clone the Repository Again
Some developers go so far as to clone the entire repository into a second folder just so they can work on two things simultaneously without interfering with each other. This works but wastes disk space, requires managing two separate remote configurations, and feels unnecessarily heavy for such a common problem.
Enter Git Worktrees: A Cleaner Solution
Git worktrees give you the ability to check out multiple branches of the same repository simultaneously, each in its own directory, all sharing the same underlying git data. Think of it as having multiple working directories attached to a single repository — without cloning anything.
The core command is straightforward:
git worktree add ../hotfix-urgent-bug hotfix/urgent-bug
This creates a new directory called hotfix-urgent-bug alongside your main project folder, checked out to the hotfix/urgent-bug branch. You can open that folder in your editor, make your changes, commit, and push — all while your original working directory stays exactly as you left it, login feature code and all. No stashing. No dirty commits. No second clone.
When you're done, cleaning up is just as easy:
git worktree remove ../hotfix-urgent-bug
How Git Worktrees Differ From Branches
This is where a lot of developers get confused at first. Worktrees are not a replacement for branches — they work together. A branch defines what code you're working on. A worktree defines where you're working on it. Every worktree is checked out to a specific branch, but the key difference is that each worktree is an independent working directory on your file system.
With regular branch switching, you have one working directory and you swap the contents of it. With worktrees, you have multiple working directories coexisting at the same time, each pointing to a different branch. Your build tools, your editor, your file watchers — they all stay pointed at their respective directories without stepping on each other.
Practical Use Cases for Git Worktrees
Beyond emergency bug fixes, worktrees shine in several everyday scenarios:
- Running two features in parallel: If you're waiting on a code review for one branch, you can start a second feature in a separate worktree instead of sitting idle or stashing mid-thought.
- Comparing behavior across branches: Need to run both the old version and the new version of an app simultaneously? Worktrees let you do exactly that, each in its own server instance.
- Testing and reviewing pull requests: Instead of stashing your work to check out a colleague's PR, spin up a worktree for it. Review their code while yours keeps running.
- Long-running builds: If your project has a slow build process, you can kick off a build in one worktree and keep writing code in another without blocking yourself.
A Few Things to Know Before You Dive In
Git worktrees are powerful, but there are a couple of limitations worth knowing. You cannot check out the same branch in two worktrees simultaneously — git will throw an error. This makes sense, since two directories modifying the same branch would create conflicts instantly. Additionally, worktrees are local to your machine, so teammates won't see them in the remote repository.
You can list all your active worktrees at any time with:
git worktree list
This gives you a clear picture of every directory currently linked to your repository and which branch each one is on.
Why Are Worktrees Suddenly So Popular?
The renewed interest in git worktrees comes down to a few factors. Developer tooling has evolved — editors like VS Code and Neovim now handle multiple project roots gracefully, making worktree-based workflows feel seamless rather than awkward. At the same time, content creators and engineering blogs have started shining a light on productivity patterns that were previously only known to power users.
There's also a cultural shift happening around developer focus and flow state. As teams recognize the real cost of interruptions and context switches, tools that minimize that friction — like worktrees — are getting a second look.
Start Using Git Worktrees Today
Git worktrees aren't a brand-new invention, but they solve a genuinely old and frustrating problem in an elegant way. If you regularly find yourself stashing work, making throwaway commits, or cloning repos just to juggle parallel tasks, worktrees are exactly what you've been missing. They're built into git, require no plugins or extra setup, and once integrated into your workflow, they make multitasking on a codebase feel natural rather than stressful. Give them a try on your next context switch — you might wonder how you ever worked without them.
