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

TaskCommand
New branch from maingit worktree add -b feat/search ../app-search main
New branch from the current commitgit worktree add -b feat/search ../app-search
Existing local branchgit worktree add ../app-login fix/login
Branch that only exists on the remotegit fetch && git worktree add ../app-pr feat/remote-only
Reset an existing branch to a new start pointgit worktree add -B feat/search ../app-search origin/main
No branch (detached HEAD), just to lookgit worktree add --detach ../app-v2 v2.0.0
Create it lockedgit 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

TaskCommand
List worktreesgit worktree list
Show locked and prunable ones, with reasonsgit worktree list -v
Machine-readable output for scriptsgit worktree list --porcelain
Status of another worktree without cdgit -C ../app-search status --short
Unpushed commits in a worktreegit -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

TaskCommand
Protect from prune and removegit worktree lock --reason "on USB drive" ../app-search
Unlockgit worktree unlock ../app-search
Move to another foldergit worktree move ../app-search ~/work/app-search
Fix links after moving the repo by handgit worktree repair

Remove

TaskCommand
Remove a clean worktreegit worktree remove ../app-search
Remove even with uncommitted files (they’re lost)git worktree remove --force ../app-search
Forget folders deleted by handgit worktree prune -v
Preview what prune would dogit worktree prune --dry-run -v
Delete the branch afterwardsgit 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 run git 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 from HEAD.
  • git config --global fetch.prune true: drop deleted remote branches on every fetch, so stale origin/* 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.