git switch

The command that moves you to another branch, updating HEAD and the working tree to match; -c creates the branch first.

In more detail

Added in Git 2.23 to take over branch switching from git checkout. git switch - goes back to the previous branch or commit, and git switch --detach moves to a commit without a branch. It refuses to switch if that would overwrite uncommitted changes.

Example

git switch -c experiment

Related terms

Taught in

References