git switch <branchname>

Switch to the specified branch

This command is useful when you need to move between different lines of development and makes it simple to update your working directory to match the target branch.

Under the hood, it adjusts HEAD to point at the given branch name and updates your index and working tree to that commit, refusing to proceed if local changes would be lost (you can stash or commit those first) and supporting -c/--create to make a new branch or -C to forcefully recreate an existing one.

Variations include git switch -c <branchname> to create and switch, git switch -C <branchname> to force-create, and git switch - to jump back to the previous branch; closely related older commands are git checkout <branchname> for switching and git checkout -b <branchname> for create-and-switch workflows.

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...