git checkout Command
git checkout The command is used for switching between different branches, restoring files, creating new branches, and other operations.
Note:The git checkout command, after Git version 2.23, introduced the git switch and git restore commands, respectively used for branch switching and file restoration, to provide clearer semantics and error checking. If you use a newer version of Git, you can consider using these commands instead of git checkout.
Switch branches:
The following command allows you to switch from the current branch to the specified branch
git checkout
For example, to switch your working directory to the main branch:
git checkout master
Create a new branch and switch:
The following command is used to create a new branch
git checkout -b
For example, create a new branch named feature-branch and switch to it:
git checkout -b feature-branch
Switch to the previous branch:
The following command lets you quickly switch back to the previous branch without having to remember the branch name:
git checkout -
Check out files:
The following command can restore a specified file in the working directory
git checkout --
Specifically, this command undoes all uncommitted changes to the file, restoring it to the state recorded by the current branch's HEAD (the latest commit).
Switch to a specific commit:
You can use the commit's hash value
git checkout
Switch to a tag:
If you have a tag
git checkout tags/
Git Basic Operations