How to Switch and Check Out Branches in Git (Checkout & Switch)
Git provides two commands for switching branches: git switch (added in Git 2.23) and the classic git checkout. Both work — git switch is recommended for new users because it has a single, clear purpose, while git checkout is still widely used and supports additional operations like restoring files.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Switching to a Local Branch
The most common operation: make an existing branch your current working branch.
# Modern (Git 2.23+)
$ git switch other-branch
# Classic
$ git checkout other-branch
To quickly jump back to the previously checked-out branch, use - as the branch name:
$ git switch -
$ git checkout -
Creating and Switching to a New Branch
Both commands can create a new branch and switch to it in a single step:
# Modern
$ git switch -c new-branch
# Classic
$ git checkout -b new-branch
You can also base the new branch on a specific starting point — another branch, a tag, or a commit:
$ git switch -c hotfix v2.1.0
$ git switch -c bugfix main
$ git switch -c experiment abc1234
Tip
Switching Branches in Tower
In case you are using the Tower Git client, switching branches becomes easy as pie. Simply double-click a branch in the sidebar to make it the new HEAD branch — or choose a branch from a list.
Checking Out a Remote Branch
You cannot switch to a remote branch directly — Git requires a corresponding local branch that tracks the remote one. First, make sure your local repository knows about the remote branch:
$ git fetch origin
Then create a local tracking branch from the remote:
# Modern: Git detects the remote branch automatically and sets up tracking
$ git switch newsletter
# Classic: explicit syntax
$ git checkout --track origin/newsletter
Either way, Git creates a local branch named newsletter that tracks origin/newsletter. From then on, git pull and git push work without any extra arguments.
Use git branch -r to list all remote-tracking branches and find the exact name to use:
$ git branch -r
origin/main
origin/newsletter
origin/feature-xyz
Tip
Checking Out Remote Branches in Tower
In case you are using the Tower Git client, tracking a remote branch is as easy as drag and drop:
git switch vs. git checkout
Both commands can switch and create branches, but they differ in scope:
| git switch | git checkout | |
|---|---|---|
| Switch branches | Yes | Yes |
| Create branches | -c flag |
-b flag |
| Restore files | No (use git restore) |
Yes |
| Detach HEAD | -d flag |
Yes (any commit) |
| Discard local changes | --discard-changes |
-f flag |
| Available since | Git 2.23 | Always |
The key advantage of git switch is clarity: it only handles branch operations, reducing the risk of accidentally overwriting files when you meant to switch branches.
# These two are equivalent:
$ git checkout -b new-feature
$ git switch -c new-feature
# These two are equivalent:
$ git checkout -f other-branch
$ git switch --discard-changes other-branch
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.