C.W.K.
Stream
Lesson 02 of 04 · published

Hotfix While Work Is Messy

~22 min · playbook, hotfix, worktree

Level 0Untracked Rookie
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Hotfix while half-done work is on the bench

The interruption pattern. You are mid-feature on feature/profile-page, with two hours of unfinished work in your editor. The on-call channel pings: production has a critical bug; main needs a one-line fix shipped immediately. The wrong move is to "just commit what I have" or to lose the in-progress work. The right move is well-rehearsed: shelter the in-progress work, branch, fix, ship, return. Total elapsed time: 15 minutes if practiced.

Two viable shelters. Stash if the work is small and short-term: git stash push -u -m "WIP: profile-page" saves both staged and unstaged work plus untracked files, leaving the tree clean. Worktree if you anticipate the hotfix taking more than half an hour, or if you want to keep editing the feature in another window: git worktree add ../repo-hotfix hotfix/login-crash main creates a parallel checkout where you can work without disturbing the feature one.

The hotfix itself is the same as any small change: branch off main, write the fix as one commit with a clear message, push, open a PR with the urgency reason in the description, get a fast review (one approver if branch protection allows), merge, deploy. Skip ceremony where ceremony is the wrong tool — but never skip the test that demonstrates the fix actually fixes the bug. A hotfix that "should work" without verification is how production gets the second outage.

The return is where teams botch this. After the hotfix lands and deploys, you must come back to the feature and pull main into it: the feature branch was based on the pre-hotfix main and now lags behind. git switch feature/profile-page, git stash pop (if you stashed) or cd ../ back to your normal worktree, git fetch origin, then git rebase origin/main. Conflicts arise only if the hotfix touched the same lines as your in-progress work, which is rare for a small fix. Keep working.

Code

Stash-based hotfix routine·bash
# Mid-feature, hotfix needed:
git stash push -u -m "WIP: profile-page (hotfix interrupt)"

# Branch off latest main:
git fetch origin
git switch -c hotfix/login-crash origin/main

# Make the one-line fix, commit, push:
git add src/auth.js
git commit -m "fix(auth): handle null user_id in /login callback"
git push -u origin hotfix/login-crash

# Open PR via gh, fast review, merge, deploy:
gh pr create --base main --title "fix(auth): handle null user_id"
# (after approval + checks green)
gh pr merge --squash --delete-branch

# Return to feature work:
git switch feature/profile-page
git stash pop                       # restore the WIP

# Catch up to the hotfixed main:
git fetch origin
git rebase origin/main
Worktree-based hotfix routine (cleaner for longer interrupts)·bash
# In your current feature worktree, no need to stash:
cd ~/code/repo

# Add a separate worktree with the hotfix branch:
git worktree add -b hotfix/login-crash ../repo-hotfix origin/main

# Work in the new worktree:
cd ../repo-hotfix
# ... make the fix ...
git commit -am "fix(auth): ..."
git push -u origin hotfix/login-crash

# After merge + deploy, retire the worktree:
cd ~/code/repo
git worktree remove ../repo-hotfix

# Pull the hotfix into the feature branch:
git fetch origin
git rebase origin/main

External links

Exercise

On any active project, simulate the interruption: make uncommitted edits to a feature branch (do not finish), then practice the entire hotfix routine — stash, branch off main, fake a one-line fix, commit, push, merge, return to the feature with stash pop, rebase. Time yourself. Then repeat using the worktree-based variant. Note in writing which felt smoother and which you would default to.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.