What does git checkout still do after git switch got introduced?
Asked Answered
H

1

19

As everyone knows, git checkout is a very overloaded command. And I do understand that certain commands got introduced to distribute, e.g. to git switch.

Before I used the following commands:

$ git checkout <existing-branch>
$ git checkout <hash>
$ git checkout -b <new-branch-name>

So I am wondering after git switch got introduced, what is the left purpose of git-checkout? Is this a deprecated command?

Hexamethylenetetramine answered 14/3, 2021 at 20:52 Comment(4)
git-checkout can also be used to restore working-tree files. (Edit: seems that you can use git-restore for that)Mica
Does this answer your question? What's the difference between git switch and git checkout <branch>Marquita
Thanks, but unfortunately, it doesn't. It only says what is beneficial with git switch, but not whats left behindHexamethylenetetramine
The git checkout command still does everything it did before, of course. :-) Actually, it's been improved: the bad behavior it used to have, destroying work, now comes out as a complaint that the command is ambiguous. (switch and restore don't have this issue.)Acetone
O
21

It's retained at least for backward compatibility. Think about millions of scripts that still use git checkout — should we hurry to rewrite all of them? Certainly no.

It's not even deprecated, actually. There is nothing about deprecation in the docs. On the other hand the docs for git restore and git switch say "THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE."

Obscene answered 14/3, 2021 at 21:2 Comment(1)
This is very useful. Because you pointed this out, I added the info about the commands being experimental in my answer here: Various ways to create a branch in git from another branchRoot

© 2022 - 2024 — McMap. All rights reserved.