git checkout
command is used in Git to switch between different branches or to restore files in your working directory.
git checkout
, you can:
git checkout -b branch-name
).
git checkout
is Multi-purpose command which can be used for switching branches and restoring files.
git switch
was introduced to simplify the process of switching branches.
git checkout
= git switch
+ git restore
git checkout
simply out of habit. However, modern teams and new documentation increasingly prefer using git switch
and git restore
for clarity.
git checkout
? git checkout feature-1
feature-1
branch, allowing you to work on it independently.
git branch
*
.
git checkout -b new-feature
new-feature
and immediately checks it out, so you can start working on it right away.
git checkout
? git checkout <branch-name>
git checkout feature-1
git checkout -b <new-branch-name>
git checkout -b login-feature
git checkout <commit-id>
git checkout 3e2f1b7
git checkout <branch-name> -- <file-path>
git checkout main -- index.html
git switch
command is used to switch between branches in a more focused and user-friendly way compared to git checkout
.
git switch
, you can:
git switch -c branch-name
.
git checkout
).
git switch
? git switch feature-1
git branch
git switch -c new-feature
new-feature
and immediately switches to it.
git switch
? git switch <branch-name>
git switch feature-1
git switch -c <new-branch-name>
git switch -c login-feature
git switch -c <new-branch-name> <commit-id>
git switch -c debug-fix 3e2f1b7
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weโre here to make our tutorials better based on your thoughts and suggestions.