Skip to main content

Command Palette

Search for a command to run...

How to create a new branch from a specific git commit.

Published
1 min read
How to create a new branch from a specific git commit.
S

Hi, I'm Satyanarayan Dalei, a mid-level Full-stack web developer from India. Currently pursuing a master's in Computer Application, I've been coding since 2020. My expertise lies in the MERN stack, and I am well-versed in the software deployment life cycle, covering both production and development environments.

Here is my git work that I was working on my next.js portfolio app where I had a need to of creating a branch from a specific git commit. It's supper easy.

  1. Get the commit id. You can use git log command or use git graph VS code extension for that.

  2. write the command like below.

     git checkout <---Commit--ID----->
    
     //example 
     git checkout 735f06f9c6a001899e5df5306a7126f337cf9ba3
    

    This will take you to that commit point.

    Now you are inside of that history point & you can create a branch from this history point.

  3. Create branch use following command

     git checkout -b new-branch
    

  4. Now you have successfully created new branch from a specific git commit

There is also a shorthand command for this

git checkout -b <---new-branch-name--> <---commit-ID--->
//example
git checout -b new-branch 735f06f9c6a001899e5df5306a7126f337cf9ba3

And that’s it! 🎉 You’ve created a new branch from a specific commit!

Happy coding! 😊