AI Hints
Home›Git & GitHub Tutorial›Going Back in Time
Git & GitHub · Lesson 29 of 144

Detached HEAD

What it means.

⏱ 2 min read▶ Video at 30:30🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

When you visit an old commit, Git says your head is detached. It sounds scary, but it's simple once you know what head is.

Detached HEAD
From the video: Detached HEAD
  • 'HEAD detached at 0ba6049'
  • Sounds scary
  • It's simple

What HEAD is

Head is just Git's way of saying, you are here. Normally, head points to a branch, like main. As you commit, main moves forward, and head moves with it. When you visit an old commit directly, head points to that commit, not a branch. That's detached. You're looking at history, not standing on a branch.

HEADyou are here
NormallyHEAD points to main
DetachedHEAD points to a commit
Fixgit switch main

Seeing HEAD

Git status tells you where head is. While detached, it says head detached at zero b a six zero four nine. Switch back to main, and status says on branch main again. Everything is normal.

git
git status
HEAD detached at 0ba6049
nothing to commit, working tree clean
git switch main
Previous HEAD position was 0ba6049 Add welcome text
Switched to branch 'main'
git status
On branch main
nothing to commit, working tree clean

Summary

Head means you are here. Detached just means you're on an old commit instead of a branch. Git switch main fixes it. Next, undoing a whole commit, safely.

Key takeaways
  • HEAD = you are here
  • Detached = on a commit, not a branch
  • git switch main
Next up: Undoing a Commit Safely — git revert