KitBench

Practical Mac, terminal, and digital workflow guides tested on real hardware.

Tested Mac and terminal guides.

3–5 minutes

Git worktrees explained: work on two branches without stashing

Use git worktree to check out multiple branches in sibling folders while sharing one Git history, avoiding risky stashes and multi-gigabyte duplicate clones.

KitBench guide cover for Git worktrees parallel branch workflow

Sources are linked in this article. Found an error? Report a correction.

git worktree attaches extra working directories to a single Git repository so you can keep a feature branch open in one folder while checking out a hotfix or pull request in a sibling folder. Every worktree shares the same .git object database and remote refs, avoiding messy git stash conflicts and duplicate repository clones.

All commands below were verified with Git 2.56.0 on Apple Silicon macOS 27.2.1.

How git worktree compares with git stash and extra clones

Switching branches inside one checkout forces your editor, language server, and test runner to re-index changed files every time. Popping a stash hours later can also collide with untracked files or updated lockfiles.

MethodDisk overheadKeeps build caches and IDE state?Shared local commits and fetches?
git stash + git switchNoneNo; triggers rebuilds and branch-switch friction.Yes (single folder).
Separate git cloneFull copy of .git history plus working treeYes; completely isolated folders.No; requires manual fetches and pushes between clones.
git worktreeWorking tree only (shared .git history)Yes; each branch has its own folder and editor window.Yes; commits are visible across all worktrees immediately.

Create, inspect, and remove worktrees cleanly

Suppose your main checkout lives at ~/code/app on a feature branch, and an urgent bug needs a fix branched off origin/main:

# 1. Fetch latest remote refs
git fetch origin

# 2. Create a sibling folder on a new branch from origin/main
git worktree add -b hotfix/login-timeout ../app-hotfix origin/main

# 3. List all active worktrees
git worktree list

Open ../app-hotfix in a second terminal tab or editor window, run tests, commit, and push while ~/code/app stays untouched. Once the fix merges, clean up the extra directory:

# Run from the main repo directory after closing editors in ../app-hotfix
git worktree remove ../app-hotfix
git branch -d hotfix/login-timeout

If you deleted a worktree directory manually in Finder without calling git worktree remove, run git worktree prune to drop the leftover reference inside .git/worktrees.

Review a pull request in a detached worktree

Git blocks checking out the same local branch name in two worktrees at once. For read-only pull request reviews or quick benchmarks, pass --detach so you do not create an extra local branch at all:

git fetch origin pull/412/head:pr-412
git worktree add --detach ../app-pr-412 pr-412

Three practical caveats to keep in mind

  • Untracked environment files such as .env do not copy over automatically because Git ignores them. Copy local config explicitly (cp .env ../app-hotfix/.env) and keep secrets out of version control.
  • Installed dependencies (node_modules, .venv) belong to each working tree. Using package managers with content-addressed stores such as pnpm or uv keeps installs fast and light on APFS storage.
  • Create worktrees beside your main repository (../app-hotfix), not inside it. Nesting a worktree under ~/code/app/worktrees/ confuses file watchers, linters, and git status unless explicitly ignored.

A tidy folder layout for teams using worktrees daily

If you keep multiple worktrees open every week, group them under a project container directory such as ~/code/myapp/main, ~/code/myapp/review, and ~/code/myapp/hotfix. This pairs well with our multi-account SSH config guide (since includeIf "gitdir:~/work/" covers all sibling worktrees inside ~/work/) and our Zsh startup optimization guide so opening extra terminal tabs stays fast.

How to verify worktree health and recover from common mistakes

Teams adopting worktrees for the first time usually run into two minor surprises: trying to check out a branch that is already open in another folder, or moving a worktree directory in Finder without telling Git. Both have safe one-command fixes.

# Check every linked worktree path and whether any directory is missing or locked
git worktree list --porcelain

# Repair links if you moved a worktree folder manually
git worktree repair ../app-hotfix

# Lock a worktree stored on an external SSD so git worktree prune will not remove it
git worktree lock --reason "Stored on external drive" /Volumes/WorkSSD/app-hotfix

If Git refuses to check out main with an error saying main is already used by worktree, you have two clean choices. Create a new branch starting from main (git worktree add -b fix/issue-12 ../app-fix main), or use --detach when you only need to inspect or test code on that commit. Avoid forcing duplicate branch checkouts with --force, because two directories updating the same branch ref independently will leave one working tree out of sync with HEAD.

Before ending a work week, run git worktree list once and remove finished review folders. Keeping only two or three active worktrees prevents stale build caches and duplicate node_modules trees from quietly eating SSD space.

Sources and verification

  • Git Documentation: git-worktree manual.
  • Verified with Git 2.56.0 on Apple Silicon macOS 27.2.1, December 2, 2026.

Stay in the loop

Get tested Mac, terminal, and workflow guides when new tutorials publish. Unsubscribe anytime.

Comments

Questions, corrections, and useful counterpoints are welcome. Keep comments specific and on topic.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.