Git: How to return from 'detached HEAD' state


If one would checkout a branch:

git checkout 760ac7e

from e.g. b9ac70b, how can one go back to the last known head b9ac70b without knowing its SHA1?


If you remember which branch was checked out before (e.g. master) you could simply

git checkout master

to get out of detached HEAD state.

Generally speaking: git checkout <branchname> will get you out of that.

If you don't remember the last branch name, try

git checkout -

This also tries to check out your last checked out branch.

Git, fatal: The remote end hung up unexpectedly

How can I revert uncommitted changes including files and folders?