I ended up with a detached head today, the same problem as described in: git push says everything up-to-date even though I have local changes
As far as I know I didn't do anything out of the ordinary, just commits and pushes from my local repo.
So how did I end up with a detached HEAD
?
try
this gives you a history of how your HEAD and branch pointers where moved in the past.
e.g. :
88ea06b HEAD@{0}: checkout: moving from DEVELOPMENT to remotes/origin/SomeNiceFeature e47bf80 HEAD@{1}: pull origin DEVELOPMENT: Fast-forward
the top of this list is one reasone one might encounter a DETACHED HEAD state ... checking out a remote tracking branch.
It can easily happen if you try to undo changes you've made by re-checking-out files and not quite getting the syntax right.
You can look at the output of
git log
- you could paste the tail of the log here since the last successful commit, and we could all see what you did. Or you could paste-bin it and ask nicely in#git
on freenode IRC.Any checkout of a commit that is not the name of one of your branches will get you a detached HEAD. A SHA1 which represents the tip of a branch would still gives a detached HEAD. Only a checkout of a local branch name avoids that mode.
See committing with a detached HEAD
For example, if you checkout a "remote branch" without tracking it first, you can end up with a detached HEAD.
See git: switch branch without detaching head
The other way to get in a git detached head state is to try to commit to a remote branch. Something like:
Note that if you do this, any further attempt to checkout origin/foo will drop you back into a detached head state!
The solution is to create your own local foo branch that tracks origin/foo, then optionally push.
This probably has nothing to do with your original problem, but this page is high on the google hits for "git detached head" and this scenario is severely under-documented.
It can happen if you have a tag named same as a branch.
Example: if "release/0.1" is tag name, then
produces detached HEAD at "release/0.1". If you expect release/0.1 to be a branch name, then you get confused.
A simple accidental way is to do a
git checkout head
as a typo ofHEAD
.Try this:
which gives