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.
Synopsis
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
| Command | Description | Example | Key Flags |
|---|---|---|---|
| git worktree add | Create a new worktree | git worktree add ../hotfix hotfix/login | -b, --detach, --lock |
| git worktree list | List all worktrees | git worktree list | --porcelain, -v |
| git worktree remove | Remove a worktree | git worktree remove ../hotfix | --force |
| git worktree move | Relocate a worktree | git worktree move ../hotfix ../fixes/login | --force |
| git worktree prune | Clean up stale metadata | git worktree prune | --dry-run, --expire |
| git worktree lock | Prevent pruning | git worktree lock ../hotfix | --reason |
| git worktree unlock | Allow pruning again | git worktree unlock ../hotfix | — |
| git worktree repair | Fix broken worktree links | git 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
| Flag | Description |
|---|---|
| -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 |
| --detach | Create the worktree with a detached HEAD |
| -f, --force | Allow adding a worktree even if the branch is checked out in another worktree |
| --lock | Lock the worktree immediately after creation |
| --reason <string> | Specify a reason for locking (requires --lock) |
| --track | Configure the new branch to track the remote branch |
| --no-track | Do not configure remote tracking |
| --guess-remote | Match the branch name to a remote tracking branch if one exists |
| --no-guess-remote | Do not try to match a remote tracking branch |
| --checkout | Check out <commit-ish> after creating the worktree (default behavior) |
| --no-checkout | Skip the checkout step — useful for configuring sparse-checkout first |
| --orphan | Create a new unparented (orphan) branch in the new worktree |
| -q, --quiet | Suppress output messages |
Create a worktree for an existing branch
# Syntax: git worktree add <path> <branch>
git worktree add ../feature-auth feature/authCreate a worktree with a new branch
# The -b flag creates the branch if it doesn't exist
git worktree add -b feature/payments ../payments mainCreate a worktree with a detached HEAD
# Useful for inspecting a specific commit or tag
git worktree add --detach ../review-v2 v2.0.0Shorthand — infer branch name from path
# If the branch "staging" exists, Git checks it out automatically
git worktree add ../stagingSee 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
| Flag | Description |
|---|---|
| --porcelain | Machine-readable output format, stable across Git versions — ideal for scripts |
| -z | NUL-terminate each line in porcelain mode (use with --porcelain) |
| -v, --verbose | Show 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) |
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.
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/logingit 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
| Flag | Description |
|---|---|
| -f, --force | Remove the worktree even if it has uncommitted or untracked changes |
# Remove a clean worktree
git worktree remove ../hotfix
# Force-remove a worktree with uncommitted changes
git worktree remove --force ../hotfixSee 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
| Flag | Description |
|---|---|
| -f, --force | Allow moving a worktree even if the destination exists or other safety checks fail |
# Move a worktree to a different directory
git worktree move ../hotfix ../fixes/login-hotfixgit 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
| Flag | Description |
|---|---|
| -n, --dry-run | Show what would be pruned without actually removing anything |
| -v, --verbose | Report all removals as they happen |
| --expire <time> | Only prune entries older than the given time (e.g. 30.days.ago) |
# 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.agogit 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
| Flag | Description |
|---|---|
| --reason <string> | Store a human-readable reason for the lock — shown in git worktree list -v |
# 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 -vgit 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 from inside the main repository
git worktree repair
# Repair and specify worktree paths explicitly
git worktree repair /new/path/to/worktree.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.
# 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 ../hotfixParallel 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.
# 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 ../notifsCode Review Checkout
Review a colleague's PR without leaving your current branch or disrupting your work.
# 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 ../reviewCI / Build Isolation
Run a full test suite or build against a different branch while you keep developing in your main worktree.
# 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-testConfiguration
Git provides several config keys that affect worktree behavior. Set them with git config.
| Flag | Description |
|---|---|
| worktree.guessRemote | When true, git worktree add without a branch argument tries to match a remote tracking branch automatically. Equivalent to --guess-remote. |
| extensions.worktreeConfig | When 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. |
# Enable automatic remote branch guessing
git config worktree.guessRemote true
# Enable per-worktree configuration
git config extensions.worktreeConfig trueRelated guides: Hooks in worktrees · .gitignore & worktrees · Bare repo + worktrees setup