GitWorktree.org logoGitWorktree.org

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

1

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.

Create hotfix worktree from main
# Still inside ~/projects/acme (feature/payments branch)
git worktree add -b hotfix/checkout-crash ../acme-hotfix main

This takes about 2 seconds regardless of repo size — worktrees share the object database with the main clone.

2

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.

Fix, commit, and push from the hotfix worktree
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-crash

The PR is opened, reviewed, and merged. Production is back to normal.

3

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.

Remove the hotfix worktree
# Back in ~/projects/acme — feature/payments is untouched
git worktree remove ../acme-hotfix
git branch -d hotfix/checkout-crash

Directory Structure

During the hotfix, the filesystem looks like this:

Filesystem layout during the hotfix
~/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 fix

Key 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.

You Might Also Like