git checkout is out, git restore and switch are in

Git version 2.23 introduced two experimental new commands to help with the confusion around the checkout command.

Can you answer without any more context what does alpha mean in the following snippet?

git checkout alpha

Is it a branch or a file? It might be both. If it is a branch, git will switch to that branch. If it is a file, git will restore its contents to HEAD.

Immediately we see the two new commands make a lot of sense.

switch is focused on switching branches (or refs in general).

examples:

git switch master                    # take me home
git switch - # take me back (last branch)
git switch -c topic # create and switch to "topic"

restore is about bringing content from other branches to the current workspace

examples:

git restore .                           # throw away all my changesgit restore --source master~2 Makefile  # restore Makefile to the second commit from mastergit restore --staged hello.c            # remove hello.c from the staging area

The new commands are much clearer and are certainly a movement towards simple vs easy. There are more commands, but there is less overlap between them.

Way to go git! Now there’s just the matter of retraining years of muscle memory 😅.

--

--