Since version 2.23 Git supports two new subcommands intended to replace the
overly-powerful and confusing checkout
.
There's a great discussion of these commands with examples here: https://github.blog/2019-08-16-highlights-from-git-2-23/
git switch
examples:
git switch branchname
to switch to (checkout) a branchgit switch -c branchname
to create and switch to a branch (likecheckout -b
)git switch -c branchname starting-point
to create and switch to a branch based onstarting-point
git restore
examples:
git restore path/to/file
to reset a file in your working copy, leaving the index intactgit restore --source=master --staged path/to/file
to put the version of a file frommaster
into your index- specify the
--worktree
option as well or instead to also put themaster
version in your local copy
- specify the
Full documentation for git switch and git restore