0

While using git I have two branches. One points to the origin/master. The other one to a different branch. In between there are a series of commits.

One commit after the origin/master there is this commit:

97bc89a  edited to build correctly

so I do

git checkout 97bc89a

and I got

you are in 'detached HEAD'

it also says that I can create a new branch by

  git switch -c <new-branch-name>

I ve never used that command before. I was going to do git checkout -b <new-branch-name>

Is it any different? How?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 1
    For difference between checkout and switch refer https://stackoverflow.com/q/57265785/8280135 – Nils Jun 15 '21 at 04:06
  • Your title question is a little odd because you have the answer in your question. :) When you are detached, both `git switch -c new-branch` and `git checkout -b new-branch` will create a new branch from your current commit. Yes, they are the same. Also, capitalizing the letter to be `checkout -B` or `switch -C` will overwrite the branch even if it already exists. – TTT Jun 15 '21 at 04:42
  • 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) – M. Justin Feb 03 '22 at 16:26

1 Answers1

1

Is it any different? How?

It isn't really different. The problem has been that checkout is so dreadfully overloaded. So, in 2019, Git was updated with two new commands, switch and restore, that do between them, with greater clarity and predictability, much of the work that checkout used to do. They are termed "experimental" but I've been using them very happily.

matt
  • 515,959
  • 87
  • 875
  • 1,141