Create new branch from a particular commit in Git

Sachinjose
1 min readJun 11, 2024

--

a Photo by DALL-E 3

Creating a new branch from a specific commit in Git is a common task and can be done using the following steps:

  1. First, identify the commit hash of the commit from which you want to branch out. You can find the commit id, by looking at the log of commits using the command IDlog.
  2. Once you have the commit id/hash, you can create a new branch with the following command:
git branch new-branch-name commit-hash

Replace new-branch-name with the name you want for your new branch, and commit-hash with the actual hash of the commit.

3. If you want to switch to the new branch immediately, you can use the checkout command:

git checkout new-branch-name

4. Or, if you can combine the creation and checkout (Step 2 & Step 3) of the new branch into one command:

git checkout -b new-branch-name commit-hash

5. To push the locally created branch into remote, use the below command.

git push -u origin <branch>

Happy Coding!

--

--