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?
In order to create a Git branch from a commit, use the “git checkout” command with the “-b” option and specify the branch name as well as the commit to create your branch from. Alternatively, you can use the “git branch” command with the branch name and the commit SHA for the new branch.
If you are allowed to rewrite the remote branch, you can use git push --force my_remote my_branch . Show activity on this post. That's right, git push -f is appropriate in the example. The reason being there's no need to re-create the entire branch, since all the commits pre-rebase remain the same.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With