detached HEAD 🌿 Git

You are in 'detached HEAD' state.

HEAD points at a commit instead of a branch, so new commits won’t belong to any branch.

Seen on: Git

Meaning

Checking out a tag, a commit hash or a remote branch directly detaches HEAD. Commits made here can be lost when you switch away unless you create a branch.

Common causes

  • git checkout <commit/tag>
  • git checkout origin/main instead of main
  • Interrupted rebase
  • CI systems checking out a specific SHA

⚡ Quick fix

  1. Create a branch to keep work: git switch -c my-work
  2. Return to a branch: git switch main
  3. Recover lost commits with git reflog

Detailed fix by platform

Git

  1. bash
    git switch -c fix-from-detached
    git reflog   # find commits made while detached

How to diagnose

  1. State — git status shows "HEAD detached at"?
  2. Commits — Any new commits to keep?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.