What is the difference between `git switch`, `git restore` and `git checkout`?
BeginnerConceptCommits, branches and tags
Answer
checkout is the older overloaded command that both changes branches and restores files. Git 2.23 split it: git switch only changes branches, git restore only restores file content from the index or a commit. Prefer the new ones for clarity.
git switch -c feature/x
git restore --staged app.py
git restore --source=HEAD~2 app.py
More on Commits, branches and tags
How do you write a good commit message?BeginnerWhat is the difference between `git add .`, `git add -A` and `git add -u`?BeginnerHow do you commit only part of the changes in a file?BeginnerHow do you change the last commit message or add a forgotten file?BeginnerWhat is the difference between lightweight and annotated tags?BeginnerHow does `git describe` work and where is it useful?Intermediate