Git prints "You are in 'detached HEAD state'"; commits appear lost after switching branches.
HEAD points at a commit instead of a branch — usually after checking out a tag, a remote branch, or a hash.
git branch rescue-work # attaches HEAD history to a new branchgit switch maingit cherry-pick <sha>Never commit while detached unless you first create a branch.
NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.
Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog