Oh wow, I didn’t know about this one. I guess it’s relatively new?
Is it just a convenience command to try and be more specific (less multi purpose) than git checkout for switching branches or does it bring any extra benefit? …I’m already quite used to my git co alias, to the point that it’s almost hardwired to my fingers by now :P
Yes git restore and git switch were made specifically to be simplified, more specific commands which are safe from performing destructive actions without warning. They were implemented in Git 2.23.0 in 2019.
2019, so 4-5 years ago so not that recent but not ancient either. But unfortunately tutorials have not been updated.
I would say that the biggest benefit of git switch is that you can’t switch to a detached state without using a flag (--detached or -d). If you do git co $tag or git co $sha-1 you may get at one point the error “you are in a detached state” which is ununderstable for begginers. To get the same error with git switch you must explicitely use git switch --detached $tag/$sha-1 which makes it much easier to understand and remember that you are going to do something unusual.
More generally it’s harder to misuse git switch/git restore. And it’s easier to explain them since the only do one thing (unlike git checkout which is a mess !).
So if it’s only for you git checkout is fine, but I would still advice to use git switch and git restore so you will have an easier time to teach/help begginers.
Oh wow, I didn’t know about this one. I guess it’s relatively new?
Is it just a convenience command to try and be more specific (less multi purpose) than
git checkoutfor switching branches or does it bring any extra benefit? …I’m already quite used to mygit coalias, to the point that it’s almost hardwired to my fingers by now :PYes
git restoreandgit switchwere made specifically to be simplified, more specific commands which are safe from performing destructive actions without warning. They were implemented in Git 2.23.0 in 2019.2019, so 4-5 years ago so not that recent but not ancient either. But unfortunately tutorials have not been updated.
I would say that the biggest benefit of
git switchis that you can’t switch to a detached state without using a flag (--detachedor-d). If you dogit co $tagorgit co $sha-1you may get at one point the error “you are in a detached state” which is ununderstable for begginers. To get the same error withgit switchyou must explicitely usegit switch --detached $tag/$sha-1which makes it much easier to understand and remember that you are going to do something unusual.More generally it’s harder to misuse
git switch/git restore. And it’s easier to explain them since the only do one thing (unlikegit checkoutwhich is a mess !).So if it’s only for you
git checkoutis fine, but I would still advice to usegit switchandgit restoreso you will have an easier time to teach/help begginers.