How to use the git switch command

Two new commands introduced in the git version 2.23, git restore and git switch. Git restore command is used to do many undo operations, read more about it here.

To switch branches we can use the git switch command. It is similar to the checkout command. The following ways we can use the git switch command.

1. To switch to an existing branch run the following command.

 git switch feature-branch

2.Create a new branch and switch to it, the -c flag creates new branch.

git switch -c new-branch

3.Return to your previously checked out branch.

git switch -

For git switch manual run the following command.

git switch --help
git switch -h

Leave a Comment