Advanced Git
Amanda Crawford-Adamo
Software and Data Engineer
Git Worktree Command
git worktree

This tables compares using git worktree vs git switch in a development workflow. $$
| Git Worktree | Git Switch |
|---|---|
| Multiple active branches | One active branch at a time |
| Separate directories | Single working directory |
| No need to stash changes | May require stashing |
Create new work tree from <branch> into directory <path>
git worktree add <path> <branch>
Example
Create a new work tree from the bugfix/data-validation branch into the ../etl-bugfix directory
git worktree add ../etl-bugfix bugfix/data-validation
git worktree list Example Output
$ git worktree list
flight-pipeline a1b2c3d [main]
flight-pipeline-feature e4f5g6h [feature]
flight-pipeline-hotfix i7j8k9l [hotfix]
git worktree remove <path> Example Output
$ git worktree remove flight-pipeline-hotfix
flight-pipeline-hotfix: deleted
When to use:
Reconsider when:
When using Git worktrees, keep these tips in mind:
Advanced Git