Sub topic 12
Shipping a Hotfix Safely
A hotfix is a production fix that cannot wait for the next regular release. This chapter assumes you know the trunk-based flow from earlier chapters: main is the source of truth, branches are short-lived, and pull requests run a check-only deployment. It also assumes you can read basic Git and Salesforce CLI commands.
Why hotfixes go through the normal path
The tempting shortcut is to edit the code directly in production or push straight to main. That skips validation and leaves production and Git out of step (org drift). The next deployment from main may then overwrite the fix, or the fix may never reach source control.
In a trunk-based flow, a hotfix is a normal change with higher priority. It branches from main, goes through a pull request and validation, and merges back into main. Because every feature branch also starts from main, in-flight work picks up the fix the next time it syncs with main. You do not need a separate hotfix branch that has to be merged back into other long-lived branches.
This works when main matches production. If unreleased work is already merged into main and must not ship yet, the hotfix cannot go out from main alone. Keep unreleased work behind feature flags, custom permissions, or custom metadata, or merge it only when it is ready to release. If you can't, cut a temporary branch from the last release tag and ship from there. Treat that as a last resort, because you must then merge the fix back into main.
The hotfix flow
Follow these steps:
- Start from an up-to-date
main, so the fix is based on what is in production. - Create a branch named
hotfix/<short-description>. - Reproduce the bug and write or update an Apex test that fails before the fix. Production deployments require tests to pass, so a fix without coverage can block the release.
- Commit the fix and open a pull request into
main. - Let the check-only deployment run local tests. Ask for review, even if it is a fast one.
- Merge, deploy to production, and tag the commit you deployed.
The commands for the branch and the tag look like this:
git switch main
git pull --ff-only origin main
git switch -c hotfix/fix-opportunity-trigger
# ...fix, commit, open a pull request into main, let validation pass, merge...
git switch main
git pull --ff-only origin main
git tag -a v2026.12.1 -m "Hotfix: opportunity trigger"
git push origin v2026.12.1The --ff-only flag makes the pull fail instead of creating a merge commit if your local main has diverged. That failure tells you your local state is wrong before you build a fix on it.
Common errors
- Fixing in production first. If the problem is truly an emergency, record exactly what you changed and commit the same change to a hotfix branch immediately. Otherwise the change is lost at the next deployment.
- Skipping the tag. Without a tag, you cannot tell which commit is in production. A tag also gives you a known point to roll back or branch from.
- Leaving feature branches behind. After the hotfix merges, ask open branches to merge or rebase from
mainso they test against the fix. - Branching from a stale
main. An old local copy can ship a fix that is missing recent changes.
Exercise
A teammate merged unreleased work into main yesterday. A production bug now needs a fix today, and the unreleased work must not ship. What are two ways to handle this?
Show answer
First, make the unreleased work inactive in production by guarding it with a feature flag, custom permission, or custom metadata, then ship the hotfix from main. Second, cut a temporary branch from the last release tag, apply and validate the fix there, deploy it, then merge the fix back into main so it is not lost.