How do I create a new Git branch from an old commit?

GitBranchCommit

Git Problem Overview


> Possible Duplicate / a more recent/less clear question
> Branch from a previous commit using Git

I have a Git branch called jzbranch and have an old commit id: a9c146a09505837ec03b.

How do I create a new branch, justin, from the information listed above?

Git Solutions


Solution 1 - Git

git checkout -b NEW_BRANCH_NAME COMMIT_ID

This will create a new branch called 'NEW_BRANCH_NAME' and check it out.

("check out" means "to switch to the branch")

git branch NEW_BRANCH_NAME COMMIT_ID

This just creates the new branch without checking it out.


in the comments many people seem to prefer doing this in two steps. here's how to do so in two steps:

git checkout COMMIT_ID
# you are now in the "detached head" state
git checkout -b NEW_BRANCH_NAME

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJZ.View Question on Stackoverflow
Solution 1 - GitbdonlanView Answer on Stackoverflow