Create a Git branch from a specific SHA

May 23, 2012

Today I will be starting to write some of the easy to use Git commands in a form of a cheat sheet to help new adopters getting on board with Git. Each post will have a specific scenario that we will be facing frequently in our day-to-day tasks and hope this can help a bit.

In some cases, you wouldn’t want to create a new branch at the HEAD because you may have a case that you want to go back in time to create a branch for backup purpose, or simply just tag a release branch that just roll out. This will be useful for this purpose. You can also do the same for tagging, but some may prefer to use a branch as they have additional bug fixes added later onto this branch.

For our example here, we also want to cherry-pick a patch fix on top of our newly created branch at a specific SHA.

Creating a new branch at specific SHA on master branch:

First fetch the latest metadata from a remote and create a branch off a specific SHA

$ git fetch <remote_name>

$ git checkout -b <local_branch_name> <SHA>

Now pick up 1 fix on top of the newly created branch

$ git cherry-pick <SHA_fix>

$ git push origin <local_branch_name>:<remote_branch_name>

This is very simple, right? :-)

Tags for this post:
  • git
  • comments powered by Disqus