Kiriakos Naiskes

Git worktrees

Tagged

Recently, I started using Git worktrees as my projects grew to the point where builds could take a few minutes. Testing changes from different branches was slowing me down, and I was losing track of what I was working on.

Here are my notes after looking into them.

What is a worktree?

  • A linked working directory attached to the same repository
  • Each worktree can check out a different branch
  • The repo shares one object database, history, and remotes
  • master clone + as many worktrees as you need
  • Not a clone: no second copy of .git, almost no extra disk usage

Why use them?

  1. Work on two branches at once without stashing
  2. Hotfix while feature work is in progress: fix it in another worktree, commit, push, go back
  3. Run long builds or tests on one branch while you keep coding on another
  4. Review a PR in a separate directory without touching your working tree
  5. Compare branches side by side in your editor
  6. Better than stashing: nothing is hidden, each branch keeps its real state on disk

Disadvantages

  1. Same branch, two worktrees: Git refuses it (which makes sense)
  2. Build artifacts don't carry over: node_modules, .venv must be reinstalled per worktree
  3. Files ignored by Git must be copied: .env files and similar files must be copied to each worktree
  4. Editor/IDE confusion: multiple roots, duplicate indexes, per-directory tool state

Takeaways

  • Worktrees = parallel branches, zero stashing
  • Perfect for hotfixes, reviews, and long-running checks
  • Cost: duplicated builds and dependencies

Cheat sheet

Task Command
Worktree with a new branch git worktree add ../repo-feat -b feature-x
Worktree for an existing branch git worktree add ../repo-hotfix hotfix-branch
Worktree at a specific commit/tag git worktree add ../repo-v1 v1.0.0
List all worktrees git worktree list
Remove a worktree (must be clean) git worktree remove ../repo-feat
Force-remove a dirty worktree git worktree remove --force ../repo-feat
Move a worktree to a new location git worktree move ../old ../new
Lock a worktree (prevent pruning) git worktree lock ../repo-feat
Unlock a worktree git worktree unlock ../repo-feat
Prune stale worktree metadata git worktree prune
Show help git worktree --help

Bare repositories

It’s possible to use bare repositories too, but they don’t fit my workflow. That’s why I don’t mention them.

Sources

Date: 2026-12-06 Sun 00:00