Git Worktree Cheat Sheet
Git worktrees are a great way to context-switch when a new priority suddenly lands on your desk. They let you multitask far more cleanly than stashing. By sharing a single .git directory, worktrees stay lightweight while preserving all the local project config you’d rather not accidentally lose. Here, a practical reference.
Core Concepts
- Shared .git directory retains project config (such as hooks, multiple remotes, etc.)
- Fresh working directory for each worktree
- Enforces branch checkout in only one worktree
Create Worktrees
Add a worktree for an existing local branch
git worktree add <path> <branch>Example: git worktree add ../app-hotfix hotfix/login-timeout
Add a worktree and create a new branch
git worktree add -b <new-branch> <path> <start-point>Example: git worktree add -b hotfix/cache-ttl ../app-hotfix main
Add a worktree from a remote-only branch
git fetchgit worktree add <path> origin/<branch>Working With Worktrees
| Command | Action |
|---|---|
git worktree list | List all worktrees |
cd <worktree-path> | Navigate into a worktree |
Removing and Cleaning Up
Remove a worktree
git worktree remove <path>Example: git worktree remove ../app-hotfix
Prune stale worktree metadata
git worktree pruneUse this if a worktree directory was deleted manually.
Common Patterns
Feature development alongside main
git worktree add ../feature-x feature/xHotfix while feature work is unfinished
git worktree add ../hotfix mainMultiple parallel hotfixes
git worktree add ../hotfix-a hotfix/agit worktree add ../hotfix-b hotfix/bRecommended Naming Convention: ../wt-<branch-name> (e.g., ../wt-hotfix-login-timeout). Your future self will appreciate this.
Back to Nerd Stuff