If all you need is to switch branches, both commands get the job done. So why does Git have two separate commands for the same thing?

git checkout used to do a lot more than just switch branches. In Git 2.23 (2019), its responsibilities were split into two focused commands:

  • git switch — branch operations
  • git restore — file operations

In other words, everything git checkout used to handle is now covered by two dedicated commands.

git checkout still works, but it's no longer recommended. Backward compatibility is preserved.

What Did git checkout Do?

The first two examples below are branch operations; the last two are file operations. One command, two completely different concerns — which is exactly why Git 2.23 drew the line.

  • git checkout feature-login — switch to a branch
  • git checkout -b feature-login — create and switch to a branch
  • git checkout -- file.txt — discard changes in a file (restore from last commit)
  • git checkout abc123 -- file.txt — restore a file from a specific commit

How Were the Commands Split?

BEFORE AFTER
git checkout feature-login git switch feature-login
git checkout -b feature-login git switch -c feature-login
git checkout -- file.txt git restore file.txt

git restore, shown in the table above, reverts a file to its state at the last commit. If you've made changes to a file and want to discard them, git restore file.txt wipes those changes out. We'll cover this command in detail in a separate post.

Why Was git switch Added?

git checkout was doing too many unrelated things, which made it a common source of confusion — especially for developers new to Git. By introducing git switch and git restore, Git clearly separates branch switching from file restoration, making the intent of each command immediately obvious.

Which One Should You Use?

For any new project, go with git switch. It's more explicit, easier to read, and reduces the risk of accidentally running the wrong operation.

That said, you'll still run into git checkout in documentation, tutorials, and legacy codebases. It's worth knowing both — Git still supports the old command, and recognizing it in the wild matters.