Switch Current Branch (2) – Git Switch
![Switching Branches Easily with git switch](/_next/image/?url=https%3A%2F%2Fstatic.d-libro.com%2F01-course-content-images%2F2041-10-Git-GitHub-Introduction%2F010-main-figures%2Fswitch-current-branch-2-git-switch-id204110050610.webp&w=1920&q=75)
git switch
is a newly introduced command as a substitute for the git checkout
command. git switch
returns the same result as git checkout
.
Comparison between git checkout and git switch
These two commands are almost the same except for some option differences. For example, the -b
option for git checkout
is the -c
option for git switch
. Below are the key commands in comparison with the git checkout
command.
Switch the current branch
git switch [existing branch name]
git checkout [existing branch name]
Create a new branch and switch to the new branch
git switch -c [new branch name]
git checkout -b [new branch name]
Forcefully switch to another branch
git switch -f [existing branch name]
git checkout -f [existing branch name]