Git switch: change branches the easy way
git switch is the modern command for navigating between branches. Clearer and safer than checkout, it's the recommended approach since Git 2.23.
What is git switch?
git switch does one thing and does it well: switch branches. It's the modern and clear version of git checkout for branch navigation.
Introduced in Git 2.23, switch cleanly separates branch navigation (switch) from file restoration (restore).
Git switch syntax
git switch branchSwitch to an existing branch
git switch -c new-branchCreate and switch to a new branch
git switch -Go back to the previous branch
Git switch in practice
Navigate between branches easily.
Basic switch
Advanced switch
git switch vs git checkout
git switch
Only for branches. Clear and unambiguous. Refuses dangerous operations by default.
git checkout
Branches + files + commits. Versatile but confusing. Can overwrite files by accident.
Common mistakes with git switch
Uncommitted changes
Switch will refuse to change branches if you have uncommitted changes that would be overwritten. Run git stash or commit first.
Branch doesn't exist
If the branch doesn't exist locally, use git switch -c to create it. If it exists on the remote, git switch will automatically create it and set up tracking.
Confusing -c and -C
-c creates a new branch (fails if it exists). -C creates or resets the branch (overwrites if it exists).
Part of the Git Branching Workflow guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git switch
Navigate between branches with GitQuest
GitQuest investigations teach you to master branch navigation.
Start the investigations