GitWorktree.org logoGitWorktree.org

Git Worktree Cheat Sheet

The complete quick-reference for every git worktree subcommand, flag, and option. Bookmark this page and come back whenever you need a reminder.

Updated March 2026
CREATEMANAGEMAINTAINCLEAN UPaddCreate a new worktreegit worktree add ../hotfix feature/fix-b--detach--trackCreates dir + checks out branchlistView all worktreesgit worktree list/proj a1b [main]/proj-fix e4f [hotfix]/proj-rev x7y [feat]--porcelainlock / unlockProtect from pruninggit worktree lock --reason "on SSD" ../portablegit worktree unlockFor external drives / NFS mountsremoveDelete worktreegit worktree remove ../fix--forceDeletes dir + refsmoveRelocate a worktreegit worktree move ../old-path ../new-pathCannot move the main worktreerepairFix broken worktree linksgit worktree repairAfter manually moving dirsGit 2.30+pruneClean stale worktree refsgit worktree prune--dry-runAfter rm -rf a worktree dirGit 2.5+ (base)Git 2.17+ (move/remove)Git 2.30+ (repair)

Synopsis

Command syntax
git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]
                 [-b <new-branch>] [-B <new-branch>]
                 [--track | --no-track] [--guess-remote | --no-guess-remote]
                 [--orphan] [-q | --quiet] <path> [<commit-ish>]
git worktree list [-v | --porcelain [-z]] [--expire <time>]
git worktree lock [--reason <string>] <worktree>
git worktree move <worktree> <new-path>
git worktree prune [-n | --dry-run] [-v | --verbose] [--expire <expire>]
git worktree remove [-f | --force] <worktree>
git worktree repair [<path>...]
git worktree unlock <worktree>

Quick Reference Table

CommandDescriptionExampleKey Flags
git worktree addCreate a new worktreegit worktree add ../hotfix hotfix/login-b, --detach, --lock
git worktree listList all worktreesgit worktree list--porcelain, -v
git worktree removeRemove a worktreegit worktree remove ../hotfix--force
git worktree moveRelocate a worktreegit worktree move ../hotfix ../fixes/login--force
git worktree pruneClean up stale metadatagit worktree prune--dry-run, --expire
git worktree lockPrevent pruninggit worktree lock ../hotfix--reason
git worktree unlockAllow pruning againgit worktree unlock ../hotfix
git worktree repairFix broken worktree linksgit worktree repair[path...]

git worktree add

Creates a new working tree linked to the same repository. Each worktree checks out a different branch, letting you work on multiple branches simultaneously without stashing or cloning.

Flags & Options

FlagDescription
-b <branch>Create a new branch and check it out in the new worktree
-B <branch>Like -b, but resets the branch if it already exists
--detachCreate the worktree with a detached HEAD
-f, --forceAllow adding a worktree even if the branch is checked out in another worktree
--lockLock the worktree immediately after creation
--reason <string>Specify a reason for locking (requires --lock)
--trackConfigure the new branch to track the remote branch
--no-trackDo not configure remote tracking
--guess-remoteMatch the branch name to a remote tracking branch if one exists
--no-guess-remoteDo not try to match a remote tracking branch
--checkoutCheck out <commit-ish> after creating the worktree (default behavior)
--no-checkoutSkip the checkout step — useful for configuring sparse-checkout first
--orphanCreate a new unparented (orphan) branch in the new worktree
-q, --quietSuppress output messages

Create a worktree for an existing branch

Existing branch
# Syntax: git worktree add <path> <branch>
git worktree add ../feature-auth feature/auth

Create a worktree with a new branch

New branch (based on main)
# The -b flag creates the branch if it doesn't exist
git worktree add -b feature/payments ../payments main

Create a worktree with a detached HEAD

Detached HEAD at a tag
# Useful for inspecting a specific commit or tag
git worktree add --detach ../review-v2 v2.0.0

Shorthand — infer branch name from path

Branch inferred from path basename
# If the branch "staging" exists, Git checks it out automatically
git worktree add ../staging

See also: git worktree add (detailed tutorial)

git worktree list

Shows every worktree associated with the repository, along with the currently checked-out branch and the HEAD commit.

Flags & Options

FlagDescription
--porcelainMachine-readable output format, stable across Git versions — ideal for scripts
-zNUL-terminate each line in porcelain mode (use with --porcelain)
-v, --verboseShow additional info such as the reason a worktree is locked
--expire <time>Only show worktrees older than the given time (e.g. 30.days.ago)
Default output
git worktree list
# Example output:
# /home/dev/project        abc1234 [main]
# /home/dev/project-hotfix def5678 [hotfix/login]
# /home/dev/project-feat   789abcd [feature/auth]

Porcelain format

Use --porcelainfor machine-readable output that is stable across Git versions — ideal for scripts.

Porcelain output
git worktree list --porcelain
# worktree /home/dev/project
# HEAD abc1234abc1234abc1234abc1234abc1234abc1234
# branch refs/heads/main
#
# worktree /home/dev/project-hotfix
# HEAD def5678def5678def5678def5678def5678def5678
# branch refs/heads/hotfix/login

git worktree remove

Removes a linked worktree and deletes its working directory. Git refuses to remove a worktree with uncommitted changes unless you pass --force.

Flags & Options

FlagDescription
-f, --forceRemove the worktree even if it has uncommitted or untracked changes
Remove worktree
# Remove a clean worktree
git worktree remove ../hotfix

# Force-remove a worktree with uncommitted changes
git worktree remove --force ../hotfix

See also: git worktree remove (detailed tutorial)

git worktree move

Moves an existing linked worktree to a new filesystem path. The main worktree (the original clone) cannot be moved with this command, and linked worktrees containing submodules cannot be moved either.

Flags & Options

FlagDescription
-f, --forceAllow moving a worktree even if the destination exists or other safety checks fail
Move worktree
# Move a worktree to a different directory
git worktree move ../hotfix ../fixes/login-hotfix
Tip: If the target path already exists, the command fails. Make sure the destination does not exist beforehand.

git worktree prune

Cleans up worktree administrative data for worktrees whose working directories have been deleted manually (e.g., with rm -rf). This does not remove worktrees that still exist on disk.

Flags & Options

FlagDescription
-n, --dry-runShow what would be pruned without actually removing anything
-v, --verboseReport all removals as they happen
--expire <time>Only prune entries older than the given time (e.g. 30.days.ago)
Prune stale metadata
# Prune stale worktree references
git worktree prune

# Dry-run: see what would be pruned without doing it
git worktree prune --dry-run

# Prune entries older than a certain time
git worktree prune --expire 30.days.ago

git worktree lock / unlock

Locking prevents git worktree prune from removing a worktree whose path is temporarily unavailable (for example, on an unmounted external drive or network share). git worktree unlock reverses the lock.

Flags & Options

FlagDescription
--reason <string>Store a human-readable reason for the lock — shown in git worktree list -v
Lock and unlock
# Lock a worktree (with an optional reason)
git worktree lock --reason "on external SSD" ../portable-wt

# Unlock it when the drive is available again
git worktree unlock ../portable-wt

# Check lock status
git worktree list -v

git worktree repair

Repairs the internal links between the main repository and its linked worktrees. This is useful after you manually move the main repository or a worktree directory without using git worktree move.

Optionally pass one or more <path> arguments to specify the new locations of worktrees that have been moved. Without arguments, Git repairs all worktrees it can find.

Repair broken references
# Repair from inside the main repository
git worktree repair

# Repair and specify worktree paths explicitly
git worktree repair /new/path/to/worktree
Note: Available since Git 2.30. On older versions, manually fix the .git file in the worktree and the corresponding entry in .git/worktrees/<name>/gitdir.

Common Workflows

Emergency Hotfix

Production is broken and you are mid-feature on another branch. Create a worktree, fix the bug, push, and clean up — your in-progress work stays untouched.

Emergency hotfix workflow
# 1. Create a worktree from main for the hotfix
git worktree add -b hotfix/login-crash ../hotfix main

# 2. Fix the bug in the new worktree
cd ../hotfix
# ... make changes ...
git add -A && git commit -m "fix: login crash on empty session"

# 3. Push and open a PR
git push -u origin hotfix/login-crash

# 4. Clean up when done
cd ../my-project
git worktree remove ../hotfix
Tip:Your in-progress feature work in the main worktree remains completely untouched — no stashing required.

Parallel Feature Development

Work on two features that touch different parts of the codebase at the same time, each with its own worktree and IDE window.

Parallel feature development
# Create two feature worktrees side by side
git worktree add -b feature/search ../search main
git worktree add -b feature/notifications ../notifs main

# Work independently in each directory
# ../search/  — search feature
# ../notifs/  — notifications feature

# List all active worktrees
git worktree list

# Clean up after merging
git worktree remove ../search
git worktree remove ../notifs

Code Review Checkout

Review a colleague's PR without leaving your current branch or disrupting your work.

Code review workflow
# Fetch the latest remote branches
git fetch origin

# Create a worktree for the PR branch
git worktree add ../review origin/feature/new-dashboard

# Review the code, run tests, etc.
cd ../review
npm test

# Done reviewing — clean up
cd ../my-project
git worktree remove ../review

CI / Build Isolation

Run a full test suite or build against a different branch while you keep developing in your main worktree.

CI / build isolation
# Create a worktree for the release branch
git worktree add ../release-test release/v3.0

# Run the build in the background
cd ../release-test
npm ci && npm run build && npm test

# Compare results, then clean up
cd ../my-project
git worktree remove ../release-test

Configuration

Git provides several config keys that affect worktree behavior. Set them with git config.

FlagDescription
worktree.guessRemoteWhen true, git worktree add without a branch argument tries to match a remote tracking branch automatically. Equivalent to --guess-remote.
extensions.worktreeConfigWhen true, each worktree reads config from $GIT_DIR/worktrees/<id>/config.worktree in addition to the shared config. Useful for per-worktree sparse-checkout settings.
Useful config settings
# Enable automatic remote branch guessing
git config worktree.guessRemote true

# Enable per-worktree configuration
git config extensions.worktreeConfig true

Related guides: Hooks in worktrees · .gitignore & worktrees · Bare repo + worktrees setup

You Might Also Like