Skip to content

git checkout / switch

Switch branch (use switch):

Terminal window
git switch branch-name
git switch -c new-branch-name
  • git switch branch-name — Go to that branch.
  • git switch -c new-branch-name — Create that branch and go to it.

Old way (same idea): git checkout branch-name and git checkout -b new-branch-name.

Restore a file (throw away your changes in that file):

Terminal window
git restore filename
git checkout -- filename

The file goes back to how it was at the last commit.