Skip to content

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 prune

Key rules ​

RuleWhy
Branch from tag, not mainAvoids pulling unreleased features into prod
Use --no-ff mergePreserves commit SHAs for cherry-pick tracking
Tag every hotfixEnables rollback and audit
Sign commits and tagsSupply-chain integrity
Fix on oldest release line firstMinimizes 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"
done

Rollback ​

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-tags
  • 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

Git Master — Git Reference for Every Skill Level