Skip to content

Git — worktrees ​

Complex Multiple working directories, one .git. Perfect for PR reviews, hotfixes, and AI agents.

Why ​

ScenarioWithout worktreeWith worktree
Hotfix while feature WIPstash or commit WIPsecond folder on main
Agent on a branchfights your dirty treeisolated path
Compare two branchesconstant switchside-by-side

List & add ​

bash
git worktree list

# new branch in sibling folder
git worktree add ../repo-hotfix -b hotfix/payment main

# existing branch
git worktree add ../repo-feature feature/login

Work & push as usual ​

bash
cd ../repo-hotfix
# edit, commit, push
git push -u origin HEAD

Remove ​

bash
# after branch is merged / done
git worktree remove ../repo-hotfix

# if folder already deleted:
git worktree prune

Rules of thumb ​

  1. One branch per worktree — don’t check out the same branch in two trees
  2. Keep agent worktrees under a convention, e.g. ../repo-.worktrees/name
  3. Clean up aggressively — worktrees accumulate disk

Useful combo ​

bash
git fetch origin
git worktree add ../repo-pr-123 origin/pr/123
# review, then remove

Linked notes ​