There are times when bug fixes must be made outside the release cycle. This is called a hotfix.
The main branches (
master) are never to be pushed directly to, and hotfixes are no excuse to violate this rule. Instead, they should be made as hotfix branches.
Hotfixes branches are just like feature branches. They're worked on in the same way: pull requests, review, merge. The only difference is that they're branched from
master instead of
# Switch to the master branch git checkout master # Create your branch git branch hotfix/security-fix # Start working!
Pull requests are made for hotfixes too, just like feature branches. A colleague will have to review and merge your pull request, ideally.
master branch will be updated once a pull request is merged in. This should trigger your automated deployment process and deploy the hotfix to production servers.
Syncing the develop branch
Once the pull request is merged,
master now has the fixes, but not
develop. In these cases, you can do one of two things:
- Option A: Merge
- Option B: Merge the hotfix into
developas well ("backporting").
Option A is preferred in most cases, with option B only being used when merging
master back may be too complicated.
There may be cases when fixes are time-sensitive and colleagues aren't available to review and merge your changes. If this happens:
- Create a pull request as usual.
- Merge the pull request yourself.
- Leave a comment in the pull request with the reason for urgency.
- Inform your teammates afterwards so they can still review your changes.
- Backporting (wikipedia.org)
Next: Why we use branches