I’m starting to learn git and the recommendation was to use git switch instead of git checkout. I know how to get to a parent commit using checkout:
git checkout HEAD~3
But when using switch like this:
git switch HEAD~3
I get the following error
fatal: a branch is expected, got commit 'HEAD~3'
>Solution :
git switch is stricter about what it operates on than git checkout. Whereas git checkout will create a detached HEAD if you try to check out something that is not a branch head, git switch will not, unless you explicitly signal your intent to do so by using the -d/--detach option.
git switch -d HEAD~3