The git switch command is a part of the Git version control system, introduced in Git version 2.23.0, released in August 2019. This command simplifies the process of switching branches and creating new ones, aiming to provide a more intuitive and streamlined user experience compared to its predecessor commands like git checkout.
git checkout
with branch names but is more explicit in its purpose.-c
or --create
flag, users can create and switch to a new branch in one command, akin to git checkout -b
.Prior to the introduction of git switch, git checkout was used for both switching branches and checking out files, leading to potential confusion. The separation of these functionalities was proposed to:
The introduction of git switch was part of a broader effort to improve Git's usability, especially for those new to version control systems. This was complemented by the introduction of git restore, which took over the file checkout operations from git checkout.
git switch feature-branch
This command would switch the current working tree to the branch named 'feature-branch'.