18

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?

HelloWorld
  • 2,392
  • 3
  • 31
  • 68
  • `git-checkout` can also be used to restore working-tree files. (Edit: seems that you can use `git-restore` for that) – Edric Mar 14 '21 at 21:00
  • 3
    Does this answer your question? [What's the difference between git switch and git checkout ](https://stackoverflow.com/questions/57265785/whats-the-difference-between-git-switch-and-git-checkout-branch) – evolutionxbox Mar 14 '21 at 21:01
  • 2
    Thanks, but unfortunately, it doesn't. It only says what is beneficial with `git switch`, but not whats left behind – HelloWorld Mar 14 '21 at 21:06
  • 2
    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.) – torek Mar 15 '21 at 09:49

1 Answers1

18

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."

phd
  • 82,685
  • 13
  • 120
  • 165
  • 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 branch](https://stackoverflow.com/a/63418267/4561887) – Gabriel Staples May 25 '22 at 17:56