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)
# Restore a file to a version 2 commits agogit checkout HEAD~2 -- filename.txt
# Discard changes in your working directorygit checkout -- filename.txt2. Switching Branches (Extended Meaning)
# Switch to an existing branchgit checkout develop3. Creating and Switching Branches (The -b Flag)
# Create a new branch and switch to it immediatelygit checkout -b feature/new-featureWhy 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:
# Exclusively for switching / creating branchesgit switch branch-namegit switch -c new-branch
# Exclusively for restoring filesgit restore filename.txtPractical Recommendations
- For new projects: Use
git switchandgit restorewhenever possible. - For legacy projects / compatibility:
git checkoutremains fully supported. - Memory trick: Think of
checkoutas “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.