AI Hints
Home›Git & GitHub Tutorial›Old Commands Online
Git & GitHub · Lesson 104 of 144

Old Commands You'll See Online

Git checkout.

⏱ 2 min read▶ Video at 1:54:32🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

When you search for Git help online, you'll often see a command called git checkout. It's older than switch and restore, and it does both jobs. It still works perfectly, so it's worth recognising.

Old Commands You'll See Online
From the video: Old Commands You'll See Online
  • Online answers use git checkout
  • Older than switch and restore
  • It does both jobs

Old and new

Here's the translation. Git checkout, a branch, is the same as git switch. Checkout dash b is switch dash c. Checkout, dash dash, and a file, is git restore. And reset head, and a file, is restore dash dash staged. Switch and restore were added in twenty nineteen, to make things clearer.

Older commandNewer equivalent
git checkout maingit switch main
git checkout -b darkgit switch -c dark
git checkout -- filegit restore file
git reset HEAD filegit restore --staged file

Checkout still works

Let's prove it. Git checkout dash b creates and switches, exactly like switch dash c. Checkout main switches back. Then we make a quick edit. Checkout, dash dash, index dot HTML throws it away, exactly like git restore. Status is clean.

git
git checkout -b dark
Switched to a new branch 'dark'
git checkout main
Switched to branch 'main'
echo 'oops' >> index.html
git checkout -- index.html
git status --short

Summary

Git checkout is the older command for both switching and restoring. Now you can read any online answer. Next, the old name for the main branch.

Key takeaways
  • checkout = switch + restore
  • checkout -b = switch -c
  • Both still work
Next up: master and main — the default branch name