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
The other way to get in a git detached head state is to try to commit to a remote branch. Something like:
git fetch
git checkout origin/foo
vi bar
git commit -a -m 'changed bar'
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.