Git Examples logoGit Examples
ListCheatsheetReviewQuizRecipesStatsSearch

git checkout -b <branchname> <commit>

Creates and switches to a new branch from a specific commit

This command is useful for starting a new line of development from a particular commit, allowing you to create and immediately switch to a new branch that begins at the specified commit rather than the current HEAD.

It works by creating a new branch named <branchname> at the commit hash or reference <commit>, and then checking out that branch so you can start working from that point in the project history.

You can use any valid commit reference for <commit>, such as a commit hash, a tag, or a branch name, and the new branch will point to that commit.

This is especially handy when you want to base your work on an earlier state of the repository or when branching off from a feature branch that isn't the current HEAD.

A closely related command is git checkout <commit> (without -b), which just checks out the commit in a detached HEAD state without creating a new branch. You can also use git switch -c <branchname> <commit> as a more modern alternative, which achieves the same result with a slightly different syntax.

Example:

git checkout -b feature-1234 some-branch
Related commands

    git checkout -b <branchname>

    git checkout -b <branchname1> <remote>/<branchname2>

    git checkout <branchname>

    git checkout -

    git checkout --<pathname>

    git checkout HEAD <pathname>

    git checkout --ours <pathname>

    git checkout --theirs <pathname>

    git checkout -m <branchname>

    git checkout <commit> -- <pathname>

    git checkout --orphan <branchname>

    git checkout -t <remote>/<branchname>

Follow me for updates: @carlesandres
ListReviewSearch

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...

Welcome to Git Examples

Git Examples is the quick way to get better at Git.

Git by Example

With more than 100 examples, you can always find a new Git secret.

Bookmark

Bookmark commands to create a personalized cheatsheet that you can print.

Deep Dive

Learn more about any Git command by clicking on the command name.

Mark for Review

Mark commands for review to revisit them later.

Take a quiz

Test your knowledge with a fun quiz.