using git worktree to work on feature branch easily
readme.mdMarkdown
readme.md
Git Worktree Cheat Sheet
What is git worktree
?
Allows you to work on multiple branches in parallel using multiple working directories.
Setup Instructions
1. Go to your main repository
cd ~/projects/your-main-repo
2. Create and add a worktree for a branch
git worktree add ../your-main-repo-feature-a feature-a
- This creates a new folder:
../your-main-repo-feature-a
- Checks out
feature-a
branch inside it - Creates the branch if it doesn't already exist
3. Add another one
git worktree add ../your-main-repo-feature-b feature-b
Now you have:
your-main-repo/
(e.g. on main)your-main-repo-feature-a/
(on feature-a)your-main-repo-feature-b/
(on feature-b)
Usage Tips
- Open each folder in a separate terminal or on your IDE window
- Work, commit, pull/push like usual in each
- No need to switch branches manually
Cleanup
Remove a worktree:
git worktree remove ../your-main-repo-feature-a
Delete the branch (optional):
git branch -d feature-a
List active worktrees
git worktree list
Full Flow
# Main repo
cd ~/projects/my-repo
# Create worktree for feature-a
git worktree add ../my-repo-feature-a feature-a
# Create worktree for feature-b
git worktree add ../my-repo-feature-b feature-b
# List all active worktrees
git worktree list
Updated: 4/16/2025