DEV Community

Cover image for Create new branch from commit ID
Tirth Patel
Tirth Patel

Posted on

Create new branch from commit ID

Many times due to unwanted push/pull/merge your branch mess up with unwanted code. Some unncessary and buggy commits line up in your branch's commit history.

In this case you wish to create new branch from last correct commit.

The naive approach is to hard reset the branch to specific commit, then create a new branch. 😏

But hold on.... You can accomplish that without the resetting stuff. 😎

Voila!!

Here are the steps :

  1. Run git log : Get the ID of commit which you want to create new branch from.

  2. Execute git checkout -b <branch_name> <commit_id>

And there you go... πŸŽ‰

Now you have created a new branch based of the commit_id that was entered in the command.

Top comments (0)