Emergency Hotfix: Zero-Interruption Bug Fix
How a four-person team shipped a production hotfix in under 15 minutes without stashing, switching branches, or losing a single line of in-progress work.
The Scenario
The Acme team is three days into building a new payments feature on the feature/payments branch. The main worktree sits at ~/projects/acme. There are uncommitted changes in three files, a half-written test suite, and a dev server running on port 3000.
Then the Slack alert fires: production checkout is crashing for 5% of users. The on-call engineer needs to fix it immediately.
Without worktrees, the options are ugly: stash everything, kill the dev server, switch to main, fix, push, switch back, pop the stash, restart the server, and hope nothing conflicts. With worktrees, there is a better way.
Timeline
Create the hotfix worktree
From the main worktree, the engineer creates a new worktree branching off main. The feature branch, dev server, and all uncommitted changes stay exactly where they are.
# Still inside ~/projects/acme (feature/payments branch)
git worktree add -b hotfix/checkout-crash ../acme-hotfix mainThis takes about 2 seconds regardless of repo size — worktrees share the object database with the main clone.
Fix the bug and push
The engineer opens a second terminal (or editor window) pointed at the hotfix worktree, finds the bug, fixes it, and pushes.
cd ../acme-hotfix
# Fix the null-pointer in checkout handler
# ... edit src/checkout/handler.ts ...
git add src/checkout/handler.ts
git commit -m "fix: guard against null cart in checkout handler"
git push -u origin hotfix/checkout-crashThe PR is opened, reviewed, and merged. Production is back to normal.
Clean up and return to the feature
Back in the original worktree, the engineer removes the hotfix worktree and picks up exactly where they left off — dev server still running, uncommitted changes intact.
# Back in ~/projects/acme — feature/payments is untouched
git worktree remove ../acme-hotfix
git branch -d hotfix/checkout-crashDirectory Structure
During the hotfix, the filesystem looks like this:
~/projects/
├── acme/ # main worktree — feature/payments branch
│ ├── .git/ # the actual Git repository
│ ├── src/
│ ├── node_modules/
│ └── ... # uncommitted changes, dev server running
│
└── acme-hotfix/ # linked worktree — hotfix/checkout-crash branch
├── .git # file pointing back to acme/.git
├── src/
└── ... # clean checkout of main + the fixKey Takeaways
- Zero context loss. The feature branch, uncommitted changes, running processes, and editor state are completely undisturbed.
- Fast creation. Creating a worktree is nearly instant because it shares the Git object store — no re-cloning, no large downloads.
- Clean separation. The hotfix happens in an isolated directory. There is no risk of accidentally committing feature-branch changes to the hotfix.
- Easy cleanup. One command removes the worktree and its directory. The branch can be deleted once merged.