LinuxCommandLibrary

git-switch

Switch between branches

TLDR

Switch to branch

$ git switch [branch]
copy
Create and switch
$ git switch -c [new_branch]
copy
Switch to previous branch
$ git switch -
copy
Create from specific commit
$ git switch -c [branch] [commit]
copy
Detach HEAD
$ git switch --detach [commit]
copy
Force switch
$ git switch -f [branch]
copy
Create orphan branch
$ git switch --orphan [branch]
copy

SYNOPSIS

git switch [options] branch

DESCRIPTION

git switch changes the current branch. Introduced in Git 2.23 to provide a focused command for branch switching, separating this concern from `git checkout` which also handles file restoration.
Use `-c` to create a new branch and switch to it in one step, or `--detach` to move to a specific commit without being on any branch.

PARAMETERS

-c, --create branch

Create new branch.
-C
Create or reset branch.
-d, --detach
Detach HEAD.
--orphan branch
Create orphan branch.
-f, --force
Force switch.
--guess
Guess remote branch.
--no-guess
Don't guess remote.
-t, --track
Set up tracking.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community