You don't know how to multitask.
You have a feature branch. Your intern pings you: "can you quickly review my PR?". You look at your terminal. You have 4 modified files, 2 staged, and a half-broken test. Congratulations. You are stuck.
What do you do? You stash everything. You checkout. You review. You checkout back. You pop the stash. You spend 10 minutes wondering why your build is broken again.
This is your life. This is fine, apparently.
Well, it's not. And git worktree has been here to save you since Git 2.5. Released in 2015. Ten years ago. You're welcome.
Instead of checking out a branch, create a worktree
Forget git checkout. Forget git switch. You don't switch branches anymore. You add a worktree.
git worktree add ../my-repo-hotfix hotfix/urgent-thing
That's it. A new folder, a different branch, alive in parallel. No stash. No stress. No crying.
my-repo/ ← your feature branch, untouched my-repo-hotfix/ ← hotfix branch, ready to go
Listing and removing worktrees
You can see all your worktrees with:
$ git worktree list /home/you/my-repo abc1234 [feature/cool-stuff] /home/you/my-repo-hotfix def5678 [hotfix/urgent-thing]
Once you're done, you delete the folder and then prune:
$ rm -rf ../my-repo-hotfix $ git worktree prune
Or you can use git worktree remove if you're feeling fancy and your worktree is clean.
A concrete example
Your workflow before worktrees:
- Drop everything.
git stash.- Hope you remember what you were doing.
- Switch branch.
- Do the thing.
- Switch back.
git stash pop.- Fix the conflicts that somehow appeared.
- Lose the will to live.
Your workflow after worktrees:
git worktree add ../my-repo-review origin/their-branch.- Open a new terminal tab.
- Do the thing.
- Close the tab.
That's four steps versus nine. You can do the math. I believe in you.
One more trick: git cd
Typing git worktree add ../my-repo-something something every time gets old fast. Let's fix that.
Add this to your .bashrc or .zshrc:
function git-cd() { local branch=$1 local repo_root=$(git rev-parse --show-toplevel) local repo_name=$(basename "$repo_root") local worktree_path="${repo_root}/../${repo_name}-${branch//\//-}" if ! git worktree list --porcelain | grep -q "refs/heads/$branch$"; then local current_branch=$(git rev-parse --abbrev-ref HEAD) git worktree add -b "$branch" "$worktree_path" "$current_branch" fi cd "$worktree_path" } git config --global alias.cd '!git-cd'
Now you just do:
git cd hotfix/urgent-thing
If the worktree doesn't exist yet, it creates it from the branch you're currently on. If it already exists, it just jumps in. Either way, you end up where you need to be.
Conclusion
git worktree won't change your life. It will just stop ruining it every time someone asks you for a quick review.
No more stash. No more lost context. No more "wait let me just save my work first". You work on two things at once, like a person who has their life together.
It's been in Git since 2015. You have no excuse.