How do you ship an urgent production hotfix with Git?
Quick Answer
Branch from the exact commit/tag that's in production (not from main, which may have unreleased changes), make the minimal fix with a test, deploy that branch, then merge or cherry-pick the fix back into main (and any active release branches) so it isn't lost in the next release.
The key thing is to branch from what's actually in production — the release tag — not from main, because main has unreleased work on it and I don't want to accidentally ship that. So I branch off v1.4.0, make the smallest possible fix plus a regression test, and deploy that branch as v1.4.1. Then I merge or cherry-pick the fix back into main and any active release branches so it doesn't get dropped when the next version goes out.
git switch -c hotfix/1.4.1 v1.4.0— start from the production tag.- Keep the change tiny and targeted — a hotfix is not the time to refactor.
- Add a regression test so the bug can't recur.
- After deploy: merge
hotfix/1.4.1intomainand any liverelease/*branches, tagv1.4.1. - The common mistake — fixing on
mainand deploying main — ships everything else that's landed since the last release.