Create a Git branch from an existing commit

Oct 03, 2022 · 1 min read · Post a comment

This post will be all about on how you could create a new Git branch from a previous commit. As everything with Git, there are multiple ways to do so.


  • Git



Once you find the commit ID (SHA1 hash) that you want to create a branch from by using the git log command to list all Git commits, run:

git checkout -b <new_branch> <commit-SHA1>

You can do the same in two steps as well:

1. git branch <new_branch> <commit-SHA1>
2. git checkout -b <new_branch>


Step 1. First, get in a detached HEAD state, by running:

git checkout <commit-SHA1>

Step 2. Now, create a new branch and check out:

git switch -c <new_branch>

or, you could the same with:

git checkout -b <new_branch>


To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.