You’re halfway through a feature when an urgent hotfix lands.
git stashis already a graveyard of entries you’re afraid to pop, andgit clonemeans waiting forever to reinstall dependencies — sound familiar?
Why Worktree Matters Even More in the Age of AI
Worktree used to mean “I can jump to a hotfix while my feature branch stays untouched.” In the AI era, it gets way more interesting —
You can have multiple Code Agents working on different features at the same time, each in its own worktree.
| |
Each worktree is an isolated workspace. Agents don’t step on each other. Just open a few terminal windows, point each Agent at its own worktree, and let them work. When they’re done, you review, PR, and merge.
What used to be three tasks done sequentially by one person is now three Agents working in parallel — and you just review. Worktree goes from “a handy branch-switching trick” to core infrastructure for AI-powered parallel development.
But first, you need to get worktree itself working smoothly. In a large monorepo, switching branches is painful:
node_modules+vendor/bundlecan be several GB — reinstalling takes minutesconfig/database.yml,master.key,.envare gitignored — gone after checkout- Different branches have different migrations — switching may require
db:migrate+db:rollback git stashwith a dozen entries? Good luck figuring out which is which
What you really want: multiple branches open at the same time, each doing its own thing.
Git Worktree does exactly that — one .git, multiple working directories, each locked to a branch. No extra clones, no stashing, true parallel development.
| |
All worktrees share the same git history — fetch and push work from any directory. But each has its own independent working tree and index.
Get Started in 30 Seconds
| |
The Real Problem: Worktrees in Large Projects Aren’t Ready Out of the Box
This is what tutorials don’t tell you. A freshly created worktree is missing a ton of gitignored stuff: database.yml, master.key, .env, vendor/bundle, node_modules…
You don’t want to run bundle install + npm install in every worktree, do you?
The fix: symlink config and dependencies from the main repo. But hand-writing scripts means hardcoded paths, poor maintainability, and rewriting for every project.
So I built gw — a lightweight Git Worktree manager that handles this for you.
gw: Worktree Management in One Step
Install
| |
Initialize Your Project
| |
.gw/links is plain text, one path per line:
| |
Daily Usage
| |
One gw add and you’re ready to rails server.
What About the Database?
Code can run in parallel, but there’s only one database. Three strategies:
- DB Dump / Load (recommended):
make dbdumpin the main repo,make dbload+db:migratein the worktree - Separate databases: use a different
database.ymlin the worktree, pointing tomyapp_dev_OA_12345 - Code-only: don’t start the server — just review code, cherry-pick, diff. No database needed.
When Should You Use It?
| Scenario | Approach |
|---|---|
| Urgent hotfix while working on a feature | ✅ worktree |
| Developing two features in parallel | ✅ worktree |
| Running a PR locally for code review | ✅ worktree |
| Quickly glancing at another branch | git stash + checkout |
| Just comparing file differences | git diff |