Git Hotfix Branches : The Final Guide

Hotfix branches are very much like release branches in that they are also meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version. When a cri…


This content originally appeared on DEV Community and was authored by ZigRazor

Hotfix branches are very much like release branches in that they are also meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version. When a critical bug in a production version must be resolved immediately, a hotfix branch may be branched off from the corresponding tag on the master branch that marks the production version.

The essence is that work of team members (on the develop branch) can continue, while another person is preparing a quick production fix.

hotfix branches

Creating the hotfix branch

Hotfix branches are created from the master branch. For example, say version 1.2.1 is the current production release running live and causing troubles due to a severe bug. But changes on develop are yet unstable. We may then branch off a hotfix branch and start fixing the problem:

$ git checkout -b hotfix-1.2.1 master
Switched to a new branch "hotfix-1.2.1"
$ ./bump-version.sh
Files modified successfully, version bumped to 1.2.1.
$ git commit -s -a -m "Bumped version number to 1.2.1"
[hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
1 files changed, 1 insertions(+), 1 deletions(-)

Don't forget to bump the version number after branching off! Again, the bumpversion. sh script will automatically determine the new version number starting from the branch name.
Then, fix the bug and commit the fix in one or more separate commits.

$ git commit
[hotfix-1.2.1-2 abbe5d6] Fixed severe production problem
5 files changed, 32 insertions(+), 17 deletions(-)

Finishing a hotfix branch

When finished, the bugfix needs to be merged back into master , but also needs to be merged back into develop , in order to safeguard that the bugfix is included in the next release as well. This is completely similar to how release branches are finished.
The one exception to the rule here is that, when a release branch currently exists, the hotfix changes need to be merged into that release branch, instead of develop .
Back-merging the bugfix into the release branch will eventually result in the bugfix being merged into develop too, when the release branch is finished.(If work in develop immediately requires this bugfix and cannot wait for the release branch to be finished, you may safely merge the bugfix into develop now already as well.)

Finally, remove the temporary branch:

$ git branch -d hotfix-1.2.1
Deleted branch hotfix-1.2.1 (was abbe5d6).

For More "The Final Guide" see the Index Page


This content originally appeared on DEV Community and was authored by ZigRazor


Print Share Comment Cite Upload Translate Updates
APA

ZigRazor | Sciencx (2021-09-21T14:19:27+00:00) Git Hotfix Branches : The Final Guide. Retrieved from https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/

MLA
" » Git Hotfix Branches : The Final Guide." ZigRazor | Sciencx - Tuesday September 21, 2021, https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/
HARVARD
ZigRazor | Sciencx Tuesday September 21, 2021 » Git Hotfix Branches : The Final Guide., viewed ,<https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/>
VANCOUVER
ZigRazor | Sciencx - » Git Hotfix Branches : The Final Guide. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/
CHICAGO
" » Git Hotfix Branches : The Final Guide." ZigRazor | Sciencx - Accessed . https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/
IEEE
" » Git Hotfix Branches : The Final Guide." ZigRazor | Sciencx [Online]. Available: https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/. [Accessed: ]
rf:citation
» Git Hotfix Branches : The Final Guide | ZigRazor | Sciencx | https://www.scien.cx/2021/09/21/git-hotfix-branches-the-final-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.