What is a detached HEAD and how do you recover work done in it?
IntermediateConceptGit internals: objects, refs and the index
Answer
HEAD contains a raw commit ID instead of a branch name, which happens when you check out a tag, a commit or a remote-tracking branch. Commits made there are not reachable from any branch and can be garbage collected eventually. To keep them, create a branch before leaving.
git switch -c rescue # while still detached
git reflog # if you already moved away
git branch rescue <sha-from-reflog>
More on Git internals: objects, refs and the index
What are the four object types in Git's object database?BeginnerIs Git a snapshot system or a diff system?BeginnerWhat is the SHA-1 (or SHA-256) hash of an object and how is it computed?BeginnerWhere does Git store objects on disk, and what are loose objects versus packfiles?IntermediateWhat exactly is a branch, and what does creating one cost?IntermediateWhat is HEAD?Beginner