Skip to content

Instantly share code, notes, and snippets.

@lukemoderwell
Created November 26, 2018 15:10
Show Gist options
  • Save lukemoderwell/12f3826dd97b6b9f8fc4fbb9b6b0fc01 to your computer and use it in GitHub Desktop.
Save lukemoderwell/12f3826dd97b6b9f8fc4fbb9b6b0fc01 to your computer and use it in GitHub Desktop.
How To Hotfix

Hotfixing is pretty simple but moving commits between different branches can get a little hairy if you're not careful. The trouble we often experience usually results from not paying attention to which branch you're on when you create the commits.

The following steps outline a recommended approach which should reduce any confusion or potential for regression.

  1. Fetch all upstream updates from the remote (e.g. Github)
$ git fetch --all 
$ git pull --all
  1. Checkout the development branch locally, then create a new topic branch for your hotfix updates.

$ git checkout -b hotfix/development

  1. Now, write the code required for your hotfix and commit them to your topic branch (e.g. hotfix/development). a. NOTE... Keep your commits small and atomic; a single commit containing all the updates is ideal. b.Make note of the commit SHA we'll need it later (e.g. 294b16b)

  2. Create a PR for your hotfix targeting the development branch & find a team member to review and merge the PR

  3. Now that development contains the hotfix, check out the release branch locally and create a new topic branch from release (e.g. git checkout -b hotfix/release). a. NOTE... This is an important step for cherry-picking commits. If you forget to checkout the target branch locally first, your PR may reflect unrelated commits.

$ git checkout release
$ git checkout -b hotfix/release
  1. Cherry-pick your commit(s) onto hotfix/release like so...

$ git cherry-pick 294b16b

[hotfix/release 294b16b] Updated to show if greater than none (zero) Author: Brian Miller [email protected] Date: Tue Sep 25 21:15:01 2018 -0400 1 file changed, 1 insertion(+), 1 deletion(-)

  1. Submit a new PR for hotfix/release targeting the release branch. When reviewing the PR, make sure that it only contains the commit(s) that you cherry-picked. For example...

https://crdschurch.slack.com/files/U0L6XJQDA/FD3N951HV/_hotfix_release__back_merge_for_294b16b_by_tcmacdonald____pull_request__337____crdschurch_crds-media.png

  1. Once merged into release, follow the same process but this time, target the master branch with your PR... a. Checkout master b. Create a topic-branch, e.g. hotfix/master c. Cherry-pick the commit d. Submit a PR e. Review for accuracy f. Find a team member to merge

And thats it– you're done. Let QA know. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment