git checkout vs git switch — Which Should You Use?

git switch was introduced to split git checkout's overloaded behavior — switching branches — into its own, less error-prone command.

Published September 27, 2026

git switch changes branches and git restore restores files; git checkout did both jobs. Modern Git recommends the clearer switch and restore commands.

How it works

checkout is overloaded: it switches branches, creates branches and discards file changes depending on arguments. Split commands reduce mistakes.

checkout still works everywhere and is needed for some older workflows.

Try it

git switch main
Switched to branch 'main'
git switch -c feature-x
Switched to a new branch 'feature-x'

Practical examples

Switch branch

git switch main

Create a branch

git switch -c feature-x

Discard file changes

git restore app.js

Old way

git checkout main
git checkout -b feature-x
git checkout -- app.js

Common mistakes

  • Using checkout -- file and losing changes without realising.
  • Mixing up branch and file arguments.
  • Using very old Git versions without switch.

Key takeaways

  • switch for branches, restore for files.
  • checkout still works.
  • Clearer commands prevent accidents.

FAQ

Since which version?

Git 2.23 introduced switch and restore.

Should I stop using checkout?

It is fine, but the new commands are clearer.

More Git articles