Home > Enterprise >  Why is there a difference between "git worktree add" with checkout and "git checkout&
Why is there a difference between "git worktree add" with checkout and "git checkout&

Time:11-03

Two commands that should, according to documentation, do the same thing, have different results, and I do not understand why nor the implication of the difference.

The First Command

git worktree add -d "c:\temp\junk\blah" 209134fc8f

Result:

c:\temp\junk\blah>git status
Not currently on any branch.
nothing to commit, working tree clean

The Second Command

git worktree add -d "c:\temp\junk\blah"
cd "c:\temp\junk\blah"
git checkout 209134fc8f

Result:

c:\temp\junk\blah>git status
HEAD detached at 209134fc8f
nothing to commit, working tree clean

I expected these two commands to give the same status result. They do not. So my questions:

Why do these two commands not have the same status result? Is there a meaningful difference between not being on any branch vs the HEAD being detached on a commit? Both seem to work the same for later commands. I am using "-d" specifically because I do not want to create a new branch for this temporary worktree.

CodePudding user response:

Why do these two commands not have the same status result?

Because git status is too clever for its own good—or maybe for your good.

  •  Tags:  
  • git
  • Related