Git 2 reference · Investigating and Tools

git worktree Command (Git)

Check out several branches at once in separate directories that share one repository, without stashing or cloning.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git worktree add PATH [-b NEW] [BRANCH]   git worktree list|remove

Parameters

ParameterDescription
add PATH BRANCH A new working directory for BRANCH.
-b NEW Create a new branch for it.
remove PATH Delete the worktree.

Examples

A second working directory
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git worktree add -q -b hotfix ../app-hotfix
git worktree list | awk '{ print $1 ~ /hotfix/ ? "hotfix worktree" : "main worktree", $3 }'

Output

main worktree [main]
hotfix worktree [hotfix]

Run this on your computer — see “Get Started” for setup.

Remove it when done
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git worktree add -q -b review ../app-review
git worktree remove ../app-review
git worktree list | wc -l

Output

1

Run this on your computer — see “Get Started” for setup.

Was this page helpful?