Modern Branch Navigation
Git 2.23 introduced git switch and git restore to split the confusing git checkout command into clearer, focused commands.
Switch vs Checkout
git checkout did too many things:
- Switch branches
- Create branches
- Restore files
- Checkout specific commits
New commands are clearer:
git switch: Change branchesgit restore: Restore files
Basic Switch
git switch main
git switch feature-branchCreate and Switch
git switch -c new-featureCreates and switches to new branch.
Switch to Previous Branch
git switch -Like cd -, returns to previous branch.
Detached HEAD
git switch --detach abc123View specific commit without affecting branches.
Restore Command
Replaces checkout for files:
git restore file.txt # Discard changes
git restore --staged file.txt # Unstage fileWhy Use Switch?
- Clearer intent
- Safer (less chance of mistakes)
- Easier to remember
- Future of Git
Checkout Still Works
git checkout isn't going away, but switch and restore are recommended for new users.
Next: Communication Protocols
You've mastered branch navigation. Next, learn Markdown—GitHub's formatting language for documentation.