← Back to Mission Control

Vessel Switching

7 min read

Git Switch Command

Mission Phase 30 • Difficulty: Beginner

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:

New commands are clearer:

Basic Switch

git switch main
git switch feature-branch

Create and Switch

git switch -c new-feature

Creates and switches to new branch.

Switch to Previous Branch

git switch -

Like cd -, returns to previous branch.

Detached HEAD

git switch --detach abc123

View specific commit without affecting branches.

Restore Command

Replaces checkout for files:

git restore file.txt          # Discard changes
git restore --staged file.txt # Unstage file

Why Use Switch?

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.