Appearance
Git Hotfix Lifecycle Quick Reference
Complete lifecycle (8 steps)
bash
# 1. Branch from last stable tag
git checkout -b hotfix/CVE-2024-9999 v4.2.0
# Or use worktree (no stash needed):
./scripts/wt-hotfix.sh CVE-2024-9999 v4.2.0
# 2. Fix and commit (signed + DCO)
git commit -sS -m "fix(auth): validate JWT expiry before session lookup
CVE-2024-9999"
# 3. Push to trigger CI (targeted test set)
git push origin hotfix/CVE-2024-9999
# 4. Tag (signed, with CVE references)
git tag -s v4.2.1 -m "v4.2.1 — CVE-2024-9999"
# 5. Deploy (tag triggers pipeline)
git push origin hotfix/CVE-2024-9999 --follow-tags
# 6. Merge back to main (no-ff, never squash)
git checkout main
git merge --no-ff hotfix/CVE-2024-9999 -m "merge: CVE-2024-9999 hotfix"
git push origin main
# 7. Cherry-pick to active release lines
for b in release/v4.2.x release/v4.1.x; do
git checkout "$b"
git cherry-pick -xs <HOTFIX-SHA>
git push origin "$b" --follow-tags
done
# 8. Clean up
git branch -d hotfix/CVE-2024-9999
git push origin --delete hotfix/CVE-2024-9999
git worktree pruneKey rules
| Rule | Why |
|---|---|
| Branch from tag, not main | Avoids pulling unreleased features into prod |
Use --no-ff merge | Preserves commit SHAs for cherry-pick tracking |
| Tag every hotfix | Enables rollback and audit |
| Sign commits and tags | Supply-chain integrity |
| Fix on oldest release line first | Minimizes cherry-pick conflicts |
CI one-liners
bash
# Detect hotfix branch in CI
[[ "$CI_COMMIT_BRANCH" =~ ^hotfix/ ]] && echo "Hotfix mode"
# List changed files for targeted testing
git diff --name-only origin/main...HEAD
# Verify tag signature in deploy
git tag -v "$TAG_NAME"
# Find hotfix merge commits
git log --merges --first-parent --oneline main | grep -i hotfix
# Backport status audit
git notes list | while read -r sha; do
git notes show "$sha" 2>/dev/null | grep -q "backported-to: release/v4.0.x" || echo "MISSING: $sha"
doneRollback
bash
# Find the hotfix merge commit
MERGE_SHA=$(git log --merges --first-parent --oneline main | grep "CVE-2024-9999" | head -1 | awk '{print $1}')
# Revert (preserves history)
git revert -m 1 "$MERGE_SHA" --no-edit
git tag -s v4.2.2 -m "v4.2.2 — revert CVE-2024-9999 (regression)"
git push origin main --follow-tagsRelated docs
- Full guide:
docs/devops-workflows/git-hotfix-lifecycle.md - Hotfix worktree script:
scripts/wt-hotfix.sh - Hotfix lifecycle script:
scripts/hotfix-manage.sh - Commit signing:
docs/recipes/signing-quick.md - Cherry-pick:
docs/recipes/cherry-pick-quick.md - Tagging:
docs/recipes/tagging-quick.md