Understanding Git Worktrees
Work on multiple branches simultaneously without the overhead of multiple clones. One repo, infinite possibilities.
Clone vs Worktree
See the dramatic difference in disk usage and workflow between multiple clones and worktrees
Multiple Clones
Traditional approach
Git Worktrees
Efficient approach
Worktrees share the same Git objects, meaning you only store the repository data once. Plus, commits are instantly visible across all worktrees!
Interactive Simulator
Click the command buttons to see how git worktree commands affect your file system in real-time
Active Worktrees (1)
Mental Model
Understand the architecture: one .git directory, multiple working directories
Main Repository
my-project/
Shared Objects
All commits, blobs, and trees are stored once in the main .git/objects directory. Worktrees reference them through symlinks.
Separate HEAD & Index
Each worktree has its own HEAD (current branch) and index (staging area), allowing independent work on different branches.
.git File Pointer
Worktrees have a .git file (not directory) that points back to the main repository's.git/worktrees/ directory.
What's inside the .git file in a worktree?
This single line tells Git where to find the actual repository data. The worktree-specific data (HEAD, index) lives in .git/worktrees/feature/ while shared data (objects, refs) remains in the main .git/ directory.
Quick Reference
Essential commands at your fingertips. Click the copy button to grab any command.
Pro Tips
Keep worktrees as siblings
Place worktrees next to your main repo, not inside it. This keeps things organized and avoids confusion.
Use descriptive paths
Name your worktree directories after their branches: ../my-project-feature-auth for the feature-auth branch.
Clean up regularly
Run 'git worktree prune' periodically to clean up references to deleted worktree directories.
No duplicate branches
You cannot have two worktrees on the same branch. This prevents conflicting work.
Common Workflow
git worktree add -b feature-auth ../feature-authCreate new worktree with new branch
cd ../feature-authNavigate to the worktree
# ... do your work, commit, push ...Work as usual, all git commands work
cd ../my-project && git worktree remove ../feature-authClean up when done