Git worktree cheat sheet: every command with examples
All the git worktree commands in one place with copy-paste examples: add a new or existing branch, list, switch, lock, move, remove, prune and repair.
Short answer: the five commands you’ll use daily are git worktree add -b <branch> <path>, git worktree add <path> <existing-branch>, git worktree list, git worktree remove <path> and git worktree prune. Everything else is below. New to worktrees? Read git worktree explained first.
Create
| Task | Command |
|---|---|
| New branch from main | git worktree add -b feat/search ../app-search main |
| New branch from the current commit | git worktree add -b feat/search ../app-search |
| Existing local branch | git worktree add ../app-login fix/login |
| Branch that only exists on the remote | git fetch && git worktree add ../app-pr feat/remote-only |
| Reset an existing branch to a new start point | git worktree add -B feat/search ../app-search origin/main |
| No branch (detached HEAD), just to look | git worktree add --detach ../app-v2 v2.0.0 |
| Create it locked | git worktree add --lock --reason "agent" -b feat/x ../app-x |
For a branch that exists only on one remote, git creates a local branch that tracks it, the same way git switch does. With -b, the path comes before the start point. Without it, the path comes before the branch.
Inspect
| Task | Command |
|---|---|
| List worktrees | git worktree list |
| Show locked and prunable ones, with reasons | git worktree list -v |
| Machine-readable output for scripts | git worktree list --porcelain |
| Status of another worktree without cd | git -C ../app-search status --short |
| Unpushed commits in a worktree | git -C ../app-search log @{upstream}..HEAD --oneline |
Switch
There is no git worktree switch. Each worktree is just a directory, so you switch by changing directory: cd ../app-search. Running git switch feat/search in another worktree fails with fatal: 'feat/search' is already used by worktree at '…', because a branch can be checked out in only one worktree at a time.
Maintain
| Task | Command |
|---|---|
| Protect from prune and remove | git worktree lock --reason "on USB drive" ../app-search |
| Unlock | git worktree unlock ../app-search |
| Move to another folder | git worktree move ../app-search ~/work/app-search |
| Fix links after moving the repo by hand | git worktree repair |
Remove
| Task | Command |
|---|---|
| Remove a clean worktree | git worktree remove ../app-search |
| Remove even with uncommitted files (they’re lost) | git worktree remove --force ../app-search |
| Forget folders deleted by hand | git worktree prune -v |
| Preview what prune would do | git worktree prune --dry-run -v |
| Delete the branch afterwards | git branch -d feat/search |
Running into errors? See how to remove a git worktree and fix the errors.
Useful settings
git config worktree.guessRemote true: when you rungit worktree add <path>with no branch name, git names the new branch after the folder. With this setting it checks out a remote branch of that name, if one exists, instead of branching fromHEAD.git config --global fetch.prune true: drop deleted remote branches on every fetch, so staleorigin/*refs don’t pile up next to your worktrees.
A naming habit that pays off
Name the folder after the branch, next to the main checkout: ~/code/app, ~/code/app-search, ~/code/app-fix-login. You’ll always know which directory holds which branch, and your editor’s recent-projects list stays readable.
Once you have more than a handful, Orchard keeps track for you. It shows every worktree in every project on your Mac, what’s uncommitted or unpushed in each, which AI agent is working where, and which ones are already in main.
FAQ
How do I create a git worktree for an existing branch?
Run git worktree add followed by the new folder path and the branch name, for example git worktree add ../app-login fix/login. The branch must not be checked out in any other worktree.
How do I switch between git worktrees?
Change directory. Each worktree is a separate folder with its own branch checked out, so cd ../app-search moves you to that worktree. There is no git worktree switch command.
How do I see all git worktrees and their state?
git worktree list shows each path, commit and branch; add -v to also see locked and prunable worktrees. It doesn’t show uncommitted changes or unpushed commits; run git status in each worktree for that.