409 words
2 minutes
Use git switch and git restore, not git checkout

I went to the library today to pick up some DVDs. Yes, I still watch DVDs at home—my 15-year-old MacBook can still play them. As I checked them out at the counter, it struck me how old-fashioned both libraries and DVDs must seem to the TikTok generation. Somehow, that thought led me straight to the command git checkout. Old habits, it turns out, are hard to give up.

Have you ever pondered this question: why does Git use checkout to mean switching and creating branches? What does “check out” actually mean?

That is a great question! Git’s checkout command has confused many developers because its name isn’t particularly intuitive.

Literal Meaning and Origins#

In everyday English, “check out” typically means:

  • Borrowing a book from a library
  • Checking out of a hotel
  • Paying and leaving at a store counter

In version control systems, the term was inherited from CVS (Concurrent Versions System), one of Git’s predecessors. In CVS:

checkout = retrieving a specific version of files from the repository into your working directory

It was analogous to “checking out” a book from a library to read and modify.

checkout in Git#

Git adopted this terminology from CVS, but overloaded it with far more responsibilities.

1. Checking Out Files (Original Meaning)#

Terminal window
# Restore a file to a version 2 commits ago
git checkout HEAD~2 -- filename.txt
# Discard changes in your working directory
git checkout -- filename.txt

2. Switching Branches (Extended Meaning)#

Terminal window
# Switch to an existing branch
git checkout develop

3. Creating and Switching Branches (The -b Flag)#

Terminal window
# Create a new branch and switch to it immediately
git checkout -b feature/new-feature

Why Is It So Confusing?#

  • Overloaded command: A single command serves three fundamentally different purposes.
  • Imperfect metaphor: Are you really “checking out” a branch or file from a repository? In practice, you are “switching contexts.”
  • Divergence from everyday English: Developer jargon vs. general language usage.

Improvements in Git 2.23+#

Because checkout was so prone to confusion, Git 2.23 introduced two dedicated commands:

Terminal window
# Exclusively for switching / creating branches
git switch branch-name
git switch -c new-branch
# Exclusively for restoring files
git restore filename.txt

Practical Recommendations#

  • For new projects: Use git switch and git restore whenever possible.
  • For legacy projects / compatibility: git checkout remains fully supported.
  • Memory trick: Think of checkout as “checking out a specific state” into your working directory—whether that state applies to a branch or a file.

Ultimately, git checkout’s naming is a historical artifact. Its scope grew far beyond its original “borrowing” concept into a multi-purpose yet confusing command. The introduction of switch and restore was specifically designed to resolve this legacy burden.

Use git switch and git restore, not git checkout
https://astro-nyc.pages.dev/posts/git-checkout-switch-restore-explained/
Author
Hari Seldon
Published at
2026-08-09
License
CC BY-NC-SA 4.0