• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / git switch

git switch

Last updated on October 6, 2020 by Sal Ferrarello

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.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Computing, Draft Tagged With: Git

Reader Interactions

Comments

  1. Ian says

    December 16, 2020 at 9:46 am

    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.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in