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
Syntax
git worktree add PATH [-b NEW] [BRANCH] git worktree list|remove
Parameters
| Parameter | Description |
|---|---|
add PATH BRANCH |
A new working directory for BRANCH. |
-b NEW |
Create a new branch for it. |
remove PATH |
Delete the worktree. |
Examples
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.
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.
Related
git switch· Switch to another branch, or create one and switch to it with -c; the modern replacement for git checkout branches.git stash· Save uncommitted changes temporarily, switch tasks, then reapply them with pop or apply.- Branches · tutorial