git switch

Switch to another branch, or create a new one and switch to it

What it does

git switch changes the current branch: the files in your folder become what they are in that branch's latest commit. With -c it creates the branch first and switches to it right away, the usual way to start a new task. git switch - takes you back to the previous branch.

Uncommitted edits come along with you, and if they get in the way (the same file differs in the other branch), git refuses to switch. Then commit the edits or put them aside with git stash. The command arrived in git 2.23; before that there were git checkout and git checkout -b, which still work.

Syntax

git switch <branch>
git switch -c <new-branch>
git switch -

Examples

Related commands

Practise · All commands