How to create a git branch from a specific commit?

To create a new branch from the existing git commit, you can execute the following command.

git checkout <base branch name>
git branch <new branch name> <commit id>

Let’s take one scenario. Support you are working on the product has version 2.x.x.x and required some changes in version 1.x.x.x.
So here you need to create a new branch from the version 1.x.x.x and needs to update and commit the changes in the new branch.

This is your last commit for version 1.x.x.x => Release version 1.x.x.x : 487b291c5bc (Commit number)
Suppose your base branch is “develop”.

So here you need to execute

git checkout develop
git branch version-1x-update 487b291c5bc

Here version-1x-update is your new branch name
Now, If you want to start a new branch (version-1x-update) at this location you have just checked out

git checkout version-1x-update

So now you are in a version-1x-update branch, you can modify your code, commit and push this new branch.

You can learn more about git commands here: A list of my commonly used Git commands.

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?