HotFixes

The hotfix release process is used often in software development. Its purpose is to allow critical fixes to be made to the main branch. When a customer finds a critical bug that has to get fixed fast, the hotfix is a good solution.

The hotfix process starts from main, and is merged back into main, but also merged into develop to keep that branch consistent. Once the hotfix mission is completed, it is destroyed as per the following diagram:

====*===*================> main
     \ /
      @====X hotfix
       \
========*================> develop
  • Here we use a 3 digit versioning system: Major.Minor.Revision, EX: 2.4.5

  • Develop branch already differs from main by a Major or Minor number

Warning

Do not release a hotfix until QA has tested it.

Preliminaries

First lets get all the version numbers in order. We’ll make bash variables for these.

  • Assume that develop is already incremented by a Major or Minor revision.

  • We use the following bash variables to reference our version numbers:

    export OLD_PROD=2.2.0 export NEW_PROD=2.2.1 export DEVELOP=2.3.0

Hotfix Workflow

The hotfix process is as follows:

  1. git checkout main

  2. git pull

  3. git checkout -b hofix/$NEW_PROD main

  4. Edit any code that references versions: change $OLD_PROD -> $NEW_PROD

  5. git commit -am “Start $NEW_PROD Hotfix: Version $OLD_PROD -> $NEW_PROD”

  6. Create a PR:

    • Squash all small commits for clarity

    • Ensure all tests pass

    • Ensure QA passes (if any)

  7. Finish the hotfix:

    • git checkout main

    • git merge –squash hotfix/$NEW_PROD

    • git push origin main

    • git branch -d hotfix/2.2.1

Using the gh CLI for HOTFIX

The gh command can make the hotfix workflow a bit easier. Here is how:

  • git checkout -b hotfix/$NEW_PROD main

  • Make needed changes to your code: version numbers and fixes

  • git commit -am “Hotfix: Fix critical issue in version $OLD_PROD”

  • Create a PR (creates pr #1234)

    gh pr create  \
       --title "Hotfix: Fix ACME-911 in $OLD_PROD" \
       --base main --head hotfix/$NEW_PROD
    
       >> Created pull request #1234
    
  • Get approval for your pr #1234

  • gh pr merge 1234

Commit Changes to Hotfix (deprecated):

Here follow a normal defect-fix process but adapted to be based on the hotfix. Once defects are made and hotfix is finished, hotfix will get merged into both main and develop branches. Details ensue:

  1. Make and commit changes needed in $NEW_PROD hotfix

    1. git flow feature start ACME-XXX hotfix/$NEW_PROD

    2. git flow feature publish

    3. work, work, commit & push

    4. make pull request from feature/ACME-XXX to hotfix/$NEW_PROD

    5. Ensure small commits are squashed: :ref:`squashing_multiple_commits`

    6. review and merge

    7. git checkout hotfix/$NEW_PROD

    8. git pull

    9. repeat for all other existing issues

  2. Make sure to clean up all features branches that are merged: Clean Git Repo Branches

Finish Hotfix After all Fixes are Made

Now all hotfix changes are made and you are ready to merge into main (and implicitly, develop).

Warning

QA must test and approve the hotfix branch before you perform the folloing steps. Make sure you have approval before releasing.

  1. UNIT TESTS MUST PASS

  2. QA has tested and approved all defects, or you have higher approval

  3. Update Release section

  4. Update Changes section

  5. git commit -am “Finish $NEW_PROD Hotfix: Version $OLD_PROD -> $NEW_PROD”

  6. git push

  7. git flow hotfix finish $NEW_PROD
    • When asked for the tag, use:

      tag $NEW_PROD
      
  8. On the entry page specify: tag $NEW_PROD

  9. You will be automatically merged into develop

  10. More than likely you will see a merge conflict with setup.py on the develop branch
    1. fix the version in setup.py to match $DEVELOP

    2. git add setup.py

    3. git commit -a # Remove any conflict log entry, assuming you resolved it

    4. git push

    5. fix any other conflicts, commit, and push

    6. git flow hotfix finish $NEW_PROD

  11. git push origin main

  12. git push origin develop

  13. git push –tags

Sanity Check

You should now be in the develop branch. Make sure all branch logs look like what you expect them to be. At the very least, make sure that:

  • git status on all branches is clean

  • main logs have the hotfix changes

  • develop logs have the hotfix changes

  • The main and develop diff has no hotfix changes:

    git diff main..develop
    

Here are some other (undocumented) commands that may be useful:

  • git status

  • git log –all -p –graph

  • git diff main –stat

  • git checkout main

  • git log –graph

  • git checkout - # (returns to develop branch)

Build the Master on CICD

If your hotfix process is not automated, you may have to run your CICD process manually. If so, do this now.