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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay