Branching Strategies for Hotfixes
You'll learn how to structure Git branches so that critical fixes reach production quickly while staying synchronized with ongoing development work.
The Core Problem
When a hotfix is needed, you must patch production code without incorporating unfinished features from your development branch. Simultaneously, you need to ensure the fix eventually makes it back into those development branches, or you'll reintroduce the bug in the next release. This requires a deliberate branching strategy.
Common Branching Approaches
Hotfix Branch from Production Tag
The most common pattern: create a hotfix/ branch directly from the production release tag (or main/master if it represents production). You fix the bug, test it, merge it back to production, then also merge it forward into your development branch (develop, main, or active feature branches).
main (production) ──┬──→ hotfix/critical-bug ──┬──→ merge to main
│ └──→ merge to develop
└──────────────────────────────→ develop (ongoing)
Git Flow Model
In Git Flow, hotfix branches come from main, get merged to both main and develop, ensuring the fix appears in both streams.
Trunk-Based with Tags
If you practice trunk-based development, you might branch from a release tag, fix it, tag a new patch version, then cherry-pick or merge the commit back to main.
The Critical Step: Merge Forward
The most common mistake is forgetting to merge the hotfix back to development branches. Without this, the next release will revert your fix. Automate this step with CI checks or required merge procedures.
Key Takeaway: Hotfix branching requires both backward integration (to production) and forward integration (to development) to prevent fixes from being lost in future releases.