News Stay informed about the latest enterprise technology news and product updates.

Git Flow hotfix branch example from start to finish

Git Flow hotfix example

Hopefully you don’t need to start a Git Flow hotfix too often. In fact, life is best if you never have to start the Git Flow hotfix process at all.

A Git Flow hotfix branch is only required when a critical bug or security flaw is found in your live, publicly facing and globally accessible application or binaries. The flaw is in a tagged commit on the Git master or main branch, and it has to be addressed immediately. The Git Flow hotfix branch creation process is the recommended workflow to address stop-the-world bugs in the master branch.

Properties of the Git Flow hotfix

Here’s the skinny on the Git Flow hotfix branch process:

  • A hotfix branch is created directly off the latest commit on master or main
  • The only commits allowed on the hotfix branch are ones that explicitly address the software bug
  • No feature enhancements or chores are allowed on the Git Flow hotfix branch
  • The hotfix branch merges into both master and develop branches when its lifecycle ends
  • The hotfix branch is deleted after it is merged or rebased into master and develop branches
gitflow hotfix example

In this Gitflow hotfix branch example we see the branch merge to master and develop before it is deleted.

Simple Git Flow hotfix example

The following Git Flow hotfix example demonstrates how hotfix process is used in a software development project.


First initialize a Git Flow based repository.

GitFlow@Example MINGW64 /c/git-flow-tutorial 
$ git flow init

Note there are only two branches in existence after the git flow init call and no tags in the recently created repository.

$ git branch -a
* develop
master

$ git tag -l

Git Flow hotfix start

We not create the hotfix branch, add a file to the repository, and then make a Git commit.

$ git flow hotfix start '0.1.1'
Switched to a new branch 'hotfix/0.1.1'

$ touch hotfix.html

$ git add .

$ git commit -m "A git flow hotfix from start to finish."
[hotfix/0.1.1 053131c] A git flow hotfix from start to finish.
1 file changed, 0 insertions(+), 0 deletions(-)

$ git branch -a
develop
* hotfix/0.1.1
master

$ git tag -l

Git Flow hotfix finish

When the Git Flow hotfix finish command is called, the commit is merged into both master and develop branches and then deleted.

$ git flow hotfix finish '0.1.1'
Switched to branch 'master'
Merge made by the 'recursive' strategy.
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
Deleted branch hotfix/0.1.1

GitFlow@Example MINGW64 /c/git-flow-tutorial  (develop)
$ ls
hotfix.html

$ git checkout master
Switched to branch 'master'

GitFlow@Example MINGW64 /c/git-flow-tutorial  (master)
$ ls
hotfix.html

Note that the hotfix branch no longer exists, and the only reminder that is was ever here is the tag left on the master branch.

$ git branch -a
develop
* master

$ git tag -l
0.1.1

Nobody likes to deal with production problems, or bugs on their main branch. But when these issues do occur, the Git Flow hotfix branch is there to guide your development efforts and ensure and urgent code changes get merged into both master and development branches.

Gitflow Hotfix Branch Diagram

The Gitflow hotfix branch is one part of the larger Git Flow workflow.

SearchAppArchitecture

SearchSoftwareQuality

SearchCloudComputing

SearchSecurity

SearchAWS

Close