I just discovered the git switch
command in early 2025, and now I always use it.
git switch
is a command used to change the current branch to another one. That's the only purpose of this command.
On the other hand, git checkout
is a command with two purposes:
- Changing branches.
- Restoring specific files.
So the difference is: git switch
is solely intended for changing branches, while git checkout
can do that and also restore files.
git switch
was introduced in Git version 2.23.0
, to split the dual-purpose git checkout
into two single-purpose commands: git switch
and git restore
.
Example usage of git switch
:
git switch feat/login
git switch -c feat/dashboard
Personally, I now always use git switch
instead of git checkout
when changing branches, because it's more explicit in its purpose — and it does only that.
Let me hear your thoughts in the comment section below!
Top comments (6)
this is extremely impressive, honestly having dedicated commands for specific actions keeps things clearer for me too you think people actually work better long-term when their commands are this explicit
Yeah, I think so. Clearer command purposes make it easier to avoid mistakes.
been cool seeing steady progress - it adds up. you think the habit sticks just cause it's easier or does something else nudge you over?
I guess it’s just easier now and everything feels a bit more clear.
Greate Post
Thank you