Command

Git Switch Branch Command

To switch to an existing Git branch, run git switch <branch>. For example, git switch feature-login selects the existing feature-login branch; replace that example name with your branch name.

Quick Answer

Command
git switch <branch>
GitCommand

Switch Branch

Type this command
git switch <branch>

Switches to an existing branch.

Tip: Older equivalent: git checkout <branch>.

Learn More

How to switch branch in Git

  1. Open the terminal or command interface for Git.
  2. Type git switch <branch>, replace any placeholders, and run it.

Tip: Older equivalent: git checkout <branch>.

What switching branches changes

Git switches to the selected branch and updates the index (staging area) and working tree to match it. New commits you create are added to that branch. The command does not create a new branch; use the separate create-and-switch command when that is your task.

Keep local changes safe

Git does not require a completely clean index and working tree before switching. It normally refuses the operation if switching would lose local changes. Read the refusal and review your changes before deciding whether to commit or stash them. Do not add --discard-changes just to bypass the refusal: that option discards local changes.

Related Git tasks

List your branches before choosing one, create a branch when it does not exist yet, or review how to stash work before switching.

Git Switch Branch Command

Run git switch <branch>.

Related Commands

Frequently asked questions

What is the Git command to switch branch?

Run git switch <branch>.

Where do I type this Git command?

Type it in the terminal or command-line interface used by Git.

Does this Git command work on Mac and Windows?

Yes. The command text is the same on both platforms when the tool is installed.

Official source · How we verify