What is ‘git switch and git restore’
It’s a command that Git has added in
Git 2.23. It works similarly to the
checkout command. But not exactly same. To understand more deeply, let’s summarize the role of checkout.
What is role of
checkout : Switch branches or restore working tree files
official docs explains checkout like above.
Git 2.23 made two other command to separate and replace this.
Two new command
- switch: switch branches
- restore: Restore working tree files
You can now write commands specifically for situations that are much more appropriate.
if you want to switch branches than we can use
git switch develop
# same as 'git checkout develop'git switch -c new-branch
# same as 'git checkout -b new-branch'
and also you can use if you restore a file
git restore README.md
# same as 'git checkout -- README.md'git restore --staged README.md
# same as 'git reset HEAD README.md'
Like this now we don’t need to use
checkout anymore :)