Skip to content

/glossary/git/detached-head

What is a detached HEAD in Git?

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
tool
Git
versions
Git 2.x
os
linux, macos, windows

Detached HEAD is the state where HEAD points directly at a commit instead of at a branch. It happens when you check out a tag, a commit hash or a remote branch such as origin/main. You can look around and even commit, but those commits belong to no branch and become hard to find once you switch away.

See it

bash
git init -q -b main repo && cd repo
echo 1 > f && git add f && git commit -qm "v1" && git tag v1.0
echo 2 > f && git commit -qam "v2"
git switch --detach -q v1.0
git status | head -1
git symbolic-ref -q HEAD || echo "HEAD is not a branch"

Output

HEAD detached at v1.0
HEAD is not a branch

Keep work done in detached HEAD

Create a branch where you are, before switching away:

bash
git init -q -b main repo && cd repo
echo 1 > f && git add f && git commit -qm "v1" && git tag v1.0
git switch --detach -q v1.0
echo hotfix > f && git commit -qam "hotfix on v1.0"
git switch -q -c hotfix-1.0
git branch --show-current
git log --oneline -1

Output

hotfix-1.0
05831c8 hotfix on v1.0

If you already switched away, git reflog shows the commit hash so you can still run git branch <name> <hash>.

Sources