Switch to a different branch in Git

CLI

Git

Branch

Switch

Luc B.

Git

Branch

Switching branches in one of the most common operations when using Git.

Code Example

Pass a branch name to git checkout to switch to a different branch.

# Checkout the master branch
git checkout master

# Checkout the dev branch
git checkout dev

More Examples

Simultaneously Create and Switch to a Branch

Use the -b flag to git checkout to create a new branch and also switch to it.

# Create and checkout my-new-branch
git checkout -b my-new-branch