Data report"State of code review 2024" is now liveRead the full report

Git switch vs Git checkout

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Git is a popular distributed version control system that helps developers track changes to their code. However, it's not uncommon for users to encounter errors. One common confusion arises between the use of git switch and git checkout commands. This guide aims to provide understanding and solutions to common issues that might arise from this confusion, impacting your Git operations.

Stop wrestling with Git commands

The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop Googling Git commands.

Learn more
  1. Understanding the differencegit checkout is a versatile command that can be used for switching branches and updating files in your working directory. On the other hand, git switch is a newer command introduced to simplify the process of switching between branches.
Terminal
# Using git checkout to switch branch
git checkout <branch-name>
# Using git switch to switch branch
git switch <branch-name>
  1. When to use which command: If you are working with a version of Git that supports the git switch command (Git version 2.23 and above), it's recommended to use git switch for changing branches and git checkout for discarding changes in your working directory.

  2. Updating your Git version: If your version of Git doesn't support the git switch command, you can update it using the appropriate command for your operating system. For example, on Ubuntu you can use sudo apt-get upgrade git.

The Graphite CLI provides an interactive checkout command gt checkout allowing you to switch branches visually.

The Graphite CLI simplifies git, handles rebasing automatically, and allows you to create, submit, and stack pull requests right from the command line.

Under the hood, the CLI runs Git to create branches, commits, and metadata, which means you can still use Git in your scripts, tooling, or whenever you feel like it. Read more about installing the Graphite CLI in our docs.

screenshot of the Graphite CLI

  • If you get an error like git: 'switch' is not a git command, it means your Git version is outdated and doesn't support the git switch command. In this case, you should update your Git version or continue using git checkout to switch branches[^codementor.io^].

  • Be careful when using git checkout to discard changes in your working directory. Make sure to commit any changes you want to keep before running this command.

The best engineers use Graphite to simplify Git

Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.

Git started for free
  • What is the difference between git switch and git checkout? git switch is a command introduced in Git version 2.23 to simplify the process of switching between branches. It separates the concerns of git checkout into two distinct commands: git switch for changing branches and git restore for discarding changes in the working directory.

  • I received an error 'git: 'switch' is not a git command'. What does it mean? This error means that your Git version does not support the git switch command. You can resolve this by updating Git to a newer version or using git checkout to switch branches[^codementor.io^].

Understanding the difference between git switch and git checkout can help you avoid confusion and errors in your Git operations. Remember to use git switch for changing branches and git checkout for discarding changes in your working directory.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2