Git 2.23
It turns out
git checkout
can do quite a lot. You can use it to change branches withgit checkout <branch>
or if you supply--branch
, create a new branch (as ingit checkout --branch <new-branch>
). If you don’t want to switch branches, don’t worry, becausegit checkout
can change individual files, too. If you writegit checkout -- <filename>
, you will reset<filename>
in your working copy to be equivalent with what’s in your index. If you don’t want to take changes from the index, you can specify an alternative source withgit checkout [treeish] -- <filename>
.The new commands, by contrast, aim to clearly separate the responsibilities of
git checkout
into two narrower categories: operations which change branches and operations which change files. To that end,git switch
takes care of the former, andgit restore
the latter.
See also: Junio C Hamano.