Git version 2.23.0
introduced a new command git switch. This command does a subset of what git checkout
does (because git checkout
does so many different things). You can continue using git checkout
for this functionality but the idea is git switch
is clearer for those starting out.
Error Message
If you get the message,
git: ‘switch’ is not a git command. See ‘git –help’.
you’re probably running an older version of git.
If the command you’re running starts with git switch -c
use git checkout -b
instead.
If the command you’re running starts with git switch
(without -c
) use git checkout
instead.
Switch to an Existing Branch
Old Way
git checkout my-branch
New Way
git switch my-branch
Create and Switch to a New Branch
This command creates a new branch and switches to it. This one command does the same thing as the two commands:
git branch my-new-branch
git switch my-new-branch
Old Way
git checkout -b my-new-branch
New Way
git switch -c my-new-branch
See Also
Git version 2.23.0
also introduced git restore.
Thank you for posting this! This was useful in helping me realize I was utilizing an older version of git. I ran the following to modernize:
brew upgrade git
Now git switch works.