Cheat Sheets · Git Cheat Sheet · Git Create Branch from Commit — Branch Off History

Git Create Branch from Commit — Branch Off History

git switch -c <new-branch> <sha>

Modern syntax: create and switch to new branch starting at

git checkout -b <new-branch> <sha>

Classic syntax: create and checkout new branch at

git branch <new-branch> <sha>

Create branch at without switching to it

Create branch from history

CommandDescription
git switch -c <new-branch> <sha>Modern syntax: create and switch to new branch starting at <sha>
git checkout -b <new-branch> <sha>Classic syntax: create and checkout new branch at <sha>
git branch <new-branch> <sha>Create branch at <sha> without switching to it

Need to experiment from an earlier release or fix a bug from a specific point in time? Create a new branch originating from any historical commit SHA.

Related Git recipes

FAQ

Can I branch off a tag instead of a commit SHA?
Yes! git switch -c hotfix-v1.0 v1.0.0 works identically with tags.

What happens to commits after that SHA?
They remain on their original branches. Your new branch diverges from the specified commit.

How do I find the commit SHA to branch from?
Use git log --oneline to locate the 7-character hash of the desired commit.

Stop memorizing — build it interactively

Build history branches in the Git Builder

Full reference: Git Cheat Sheet