Loading lessons...
Git Worktrees
Git Worktrees
A worktree is an extra working folder linked to the same repository, checked out to a different branch.
The classic problem
Without worktrees, to work on another branch you must stash or commit your current changes first, because you cannot have two branches checked out in the same folder.
What a worktree does
git worktree add ../my-project-hotfix hotfix-branch
This creates a new folder named my-project-hotfix with the hotfix-branch checked out, while your main folder keeps its own branch.
Why use worktrees?
- Work on multiple branches at the same time.
- Open two editors on different features.
- Switch contexts instantly, no stashing needed.
- Useful for testing release branches while developing.
List worktrees
git worktree list
Remove a worktree
git worktree remove ../my-project-hotfix
The branch stays in the repository, only the folder is removed.
TL;DR
- A worktree is an extra folder for another branch of the same repo.
git worktree add path branchcreates one.- Work on multiple branches simultaneously without stashing.
git worktree listandgit worktree removemanage them.