If you are working on a branch and that branch has a history that you want to split off into another branch then there are a few possibilities.
Assuming you have the branch you want to split off from you can create a new branch using the commit hash of the commit you want to branch from.
git branch new_branch_name <sha1-of-commit>It's possible to use the symbolic reference of the commit from the head of the branch. The following will generate a branch from the previous commit.
git branch new_branch_name HEAD~1If you want to split off and checkout the branch at the same time you can use checkout.
git checkout -b new_branch_name <sha1-of-commit or HEAD~1>The more recent switch command is also able to perform this action.
git switch -c new_branch_name <sha1-of-commit or HEAD~1>All of these actions will generate a branch called new_branch_name, with the previous branch remaining in place.
Add new comment