How to switch branches?

git switch branch_name

To switch to an existing branch called branch_name use git switch branch_name.

The switch command was introduced with git version 2.23. In older versions of git, you will need to use git checkout.

Layer 1
Terminal Example
git branch -v
* main        9b3e5ec readme
  test-branch 120f7ab Adding tests

git switch test-branch
Switched to branch 'test-branch'

See git switch to learn more about it.

Last modified on November 30, 2021.

You might also like