10

git status says:

HEAD detached at e1997bd

and git rev-parse HEAD says:

e1997bd

What's the meaning of this?

I was thinking HEAD detached means HEAD is not pointing to to branch tip.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • possible duplicate of [How can I reconcile detached HEAD with master/origin?](http://stackoverflow.com/questions/5772192/how-can-i-reconcile-detached-head-with-master-origin) – Buddy Jul 16 '15 at 16:06
  • See this answer: http://stackoverflow.com/questions/25670173/why-does-git-tell-me-not-currently-on-any-branch-after-i-run-git-checkout-ori/25670296#25670296 – jub0bs Jul 16 '15 at 17:38

1 Answers1

17

Read through: http://gitolite.com/detached-head.html

You can also look at: http://gitolite.com/gcs.html#(48)

The head points to the commit, that's not the problem. The problem is that it's no longer a reference to a local branch name. It's the actual SHA1 hash of the commit.

This may have happened if you did:

git checkout <commit_id>
  -- or --
git checkout origin/master

To fix this, do

git checkout <branch_name>
Mircea
  • 10,216
  • 2
  • 30
  • 46
  • 1
    Can also happen if you checkout a remote tracking branch e.g. origin/master – brettwhiteman Jul 16 '15 at 21:42
  • I did `git checkout ` but it doesn't recognize any remote branches. Trying to checkout another branch gives the same error as trying to get a new commit. `pathspec did not match any file(s) known to git` – Zim Feb 07 '22 at 19:49