Switch branches in git with... `git switch`
It's experimental. It's intuitive. It's in the newest version of git
, version 2.23.0. It is:
git switch my-branch
And, with every git command there are many ways to use the command with many flags:
You might want to create a branch and switch to it:
git switch -c new-branch
You might want to switch to a new version of a local branch that tracks a remote branch:
git switch -t origin/remote-branch
You can throw away unstaged changes with switching by using -f
.
git switch -f other-branch
I feel that if I were learning git from scratch today, this would be much easier to learn, there's just so much going on with checkout
.