
Git Worktrees: Work on Multiple Flutter Branches Simultaneously
SATURDAY AUGUST 16 2025 - 2 MIN
The context-switching tax
You're knee-deep in a new feature – state management wired up, widgets looking good, tests passing. Then Slack pings: "Production bug. Needs a hotfix NOW."
You know the drill:
git stash
git checkout main
git checkout -b hotfix/critical-issue
# fix the bug, test it, push it
git checkout feature/new-feature
git stash pop
# pray your IDE catches up
By the time you're back, your IDE is re-indexing, the emulator needs a fresh run, and you've lost your train of thought. The context switch costs 15 minutes minimum.
Worktrees: multiple branches, zero stashing
Git worktrees let you check out different branches in separate directories from the same repo. No stashing, no branch switching, no waiting for IDE re-indexing.
Here's the setup:
# Your main working directory
~/Code/my_app/
# Create a worktree for the hotfix in a parallel directory
git worktree add ../my_app-hotfix main
Now you have:
~/Code/my_app/ # Your feature branch (untouched)
~/Code/my_app-hotfix/ # Fresh main branch checkout
Open the hotfix directory in a new IDE window, fix the bug, commit, push. Your feature branch keeps running in the original window. Zero interruption.
Real-world Flutter scenarios
Scenario 1: Code review while working
PM needs you to review a PR but you're mid-refactor with uncommitted changes everywhere.
git worktree add ../my_app-review feature/teammate-pr
Open it, review the code, run the app, leave comments. Your main work stays untouched.
Scenario 2: Compare behavior across branches
"This button worked on main but broke on my branch."
git worktree add ../my_app-main main
Run both apps side-by-side. Instant comparison. No guessing, no stashing.
Scenario 3: Long-running experiments
You want to try a new architecture pattern but don't want to commit to it yet.
git worktree add ../my_app-experiment -b experiment/new-arch
Work on it for days. If it works, merge it. If not, delete the worktree. Your main branch never saw the chaos.
Commands you'll actually use
# Create a new worktree from an existing branch
git worktree add <path> <branch>
# Create a worktree with a new branch
git worktree add <path> -b <new-branch>
# List all worktrees
git worktree list
# Remove a worktree when you're done
git worktree remove <path>
# or just delete the directory and run
git worktree prune
Things to know
- Shared commits: All worktrees share the same repository. A commit in one worktree is visible in all others after a
git fetch. - One branch per worktree: You can't check out the same branch in multiple worktrees. Git prevents this to avoid conflicts.
- IDE quirks: VS Code and Android Studio handle worktrees fine – just open each as a separate window. IntelliJ IDEA might complain about duplicate projects; ignore it.
- pub get runs independently: Each worktree needs its own
flutter pub get. They don't sharebuildor.dart_toolfolders.
Clean-up
When you're done with a worktree:
git worktree remove ../my_app-hotfix
Or just delete the folder and prune:
rm -rf ../my_app-hotfix
git worktree prune
Why this matters
Before worktrees I avoided urgent fixes because the mental overhead of stashing and switching was too high. Now I keep 2-3 worktrees active:
my_app– main feature workmy_app-hotfix– quick fixes and reviewsmy_app-experiment– risky ideas
I bounce between them instantly. No stashing. No waiting. No lost context.
If you frequently switch branches or need to compare behavior across branches, worktrees are a game-changer. Try it once and you won't go back.
For suggestions and queries, just contact me.