git worktree
git
Usage
git worktree add <path> [<branch>]Checks out a second working folder from the same repository so you can build two branches at once without cloning again; the same branch cannot be checked out twice, and deleting the folder by hand leaves an entry until prune.
Common flags
| Flag | Meaning |
|---|---|
| add <path> <branch> | check that branch out into another folder |
| add -b <new> <path> | create a branch and check it out there |
| list | show every working tree of this repository |
| remove <path> | delete a working tree cleanly |
| prune | forget trees whose folder you deleted by hand |
| --detach | check out a commit without a branch |
Examples
git worktree add ../hotfix hotfix/logina second folder on another branch, sharing one .git
git worktree add -b release ../rel maincreates release from main in ../rel
git worktree remove ../hotfixremoves the folder and its bookkeeping entry
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git worktree do?
Checks out a second working folder from the same repository so you can build two branches at once without cloning again; the same branch cannot be checked out twice, and deleting the folder by hand leaves an entry until prune.
Q. How do I type it?
git worktree add <path> [<branch>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-worktree