git switch Move to another branch
Changes the branch you are working on, updating your files to match. It is a clearer, safer replacement for the branch-switching part of git checkout.
Synopsis
git switch [OPTION]... BRANCH
git switch -c NEW-BRANCH [START-POINT]
Common options
| Option or form | What it does |
|---|---|
-c NAME | Create a new branch and switch to it |
- | Switch back to the previous branch |
-d, --detach | Check out a commit without a branch, to look around |
--track | When switching to a remote branch, set up tracking |
-f, --discard-changes | Throw away local changes to switch |
Examples
git switch main
Switched to branch 'main'
git switch -c feature/search
git switch -c hotfix v1.2.0
git switch -
git switch feature/login
Notes
- If you have uncommitted changes that clash with the target branch, Git refuses. Commit or stash first.
- If only one remote has a branch with that name, git switch NAME creates a tracking branch for it.
- Available in Git 2.23 and later.
See also
Last reviewed 2026-10-09.