If you’ve been using Git for a while you’re probably used to the ubiquitous
git checkout command, which is somewhat overloaded in what it’s doing. You can use
checkout to switch branches, create branches, update the working tree to a past commit, wiping working tree changes, and a few more things. Put simply, this command has too many responsibilities, and should be refactored.
This is what happened in Git
2.23.0: We can now use two other, more specialized commands,
git switch and
git switch is used to managed branches, that is creating a branch or switching to a branch. It is complementary with
git branch, which lists, deletes, and (also) creates branches.
git switch as follows:
git restore is used to restore working tree files, in the same way you would have used
git checkout to checkout or restore a certain working tree state. Here are some examples for
This post has been reposted from my newsletter issue 041.