Grow a New Tree with Git Worktrees
Feb 23, 2026 · 5 min read
The Interruption
I was deep in a refactor. The screen was a blur of green and red. My brain was locked on one goal. Then Slack pinged. A production bug. The kind that makes my heart jump. The fix was needed right now. I ran git status and felt my stomach drop. Uncommitted changes everywhere. Half done work. Files moved around. Experiments I did not want to explain to anyone. I did what people do in a panic. I made a quick branch and dumped my mess there, just so I could switch to the urgent fix. When I came back, I hit a merge conflict with my own unfinished work. I was fighting my past self, and I was losing. > [!NOTE] Git Worktrees fixed this problem for me. They let me keep my feature work exactly as it is, and still jump to an urgent task in a clean folder.
What is a Git Worktree?
In a normal Git setup, you have one working folder. When you switch branches, Git swaps the files inside that same folder. A Git worktree lets one repository have more than one working folder. Each folder is tied to one branch or one commit. You do not have to clone the repo again. The folders share the same Git history stored in the .git area, so they stay light and fast. Think of it like this: Instead of one desk where you keep clearing space for a new task, you get a second desk that already has the right files on it. > [!TIP] Quick Glossary: > - Branch: A separate line of work. > - Commit: A saved checkpoint. > - Stash: A temporary place to park changes.
The Hotfix Moment, Solved
Here is the flow that keeps your feature work safe and your hotfix clean. 1. Stay in your feature folder. Do not stash. Do not commit. Just leave your changes where they are. 2. Create a new worktree in a separate folder for the hotfix. This example creates a new branch called hotfix/prod123 from main. (If your default branch is master, replace main with master.) 3. Move into the new folder and do the fix. 4. Commit and push the fix like normal. 5. Remove the worktree folder when the emergency is over. Go back to your feature folder. Your files are still exactly as you left them.
The Main Commands
You only need a few commands to get value from worktrees. ### Create a worktree Create a new branch for the worktree (common for hotfixes): Use an existing branch (common for reviews): ### See all worktrees ### Remove a worktree ### Clean up stale entries If you delete a worktree folder by hand, Git can keep a record of it. prune removes those leftovers.
Best Times to Use Worktrees
The Urgent Hotfix: You are mid feature and a production fix shows up. Keep your feature folder messy and open a clean hotfix folder. - Code Reviews: You need to review a teammate's branch. Open it in a new folder, run it, and close it when done. - Parallel Execution: You want to run a slow build or test run and keep coding at the same time in another folder. - A/B Testing Local: You want to compare two versions of the app side by side on your machine. Put each version in its own folder.
Rules That Keep This Stress-Free
One branch per worktree. A branch can only be checked out in one worktree at a time. This helps avoid accidents. 2. Create worktree folders next to your main repo folder, not inside it. This keeps things easy to see and easy to delete. 3. Name your folders explicitly so you know what they are for (e.g., myrepohotfix or myreporeview). 4. Remove worktrees when you are done with them. Your history stays safe in the main repository. 5. Mistakes happen. If a worktree folder is deleted by mistake, run git worktree prune to clean up the record.
Extra Tricks You May Like
These are optional, but they can be useful once you get comfortable. ### Make a temporary worktree If you just want a scratch folder for quick testing, you can create a worktree that is not tied to a branch. ### Lock a worktree If a worktree lives on a drive that is not always plugged in, you can lock it so Git does not prune its record. ### Move or repair a worktree If you want to relocate a worktree folder, use move. If paths get out of sync, repair can help.
Wrap Up
Worktrees turned my worst context switch into a simple routine. I keep my feature mess untouched. I open a clean folder for the urgent fix. I ship it. Then I delete that folder and go right back to where I was. Next time the hotfix message hits, you do not need to gamble with stashes or messy commits. Just grow a new tree.
Recommended Resources
Further Reading: > 1. Official Git Documentation: git-worktree > 2. Morgan.cloud: Git worktrees - the best Git feature you've never heard of > 3. DataCamp: Git Worktree Tutorial - Work on Multiple Branches Without Switching