Core Git 4/8

HEAD

HEAD tells Git what is currently checked out. Most of the time HEAD points to a branch name, so switching branches moves HEAD and changes your working context. Sometimes HEAD points directly to a commit instead, which is called detached HEAD mode and is useful for safe inspection of older history.

Back to Git Concepts overview

HEAD - The "You Are Here" Marker

HEAD is Git's "you are here" marker. It follows the branch you currently have checked out, and switching branches moves HEAD from one branch label to another.

a1b2c3d b2c3d4e c3d4e5f d4e5f6g e5f6g7h f6g7h8i COMMAND RUN > git switch main HEAD main feature COMMAND RUN > git switch feature main HEAD feature HEAD follows the current branch, and that branch points to a commit.

Detached HEAD State

In detached HEAD state, HEAD points directly to a commit instead of to a branch label. This is useful for temporary inspection, but commits you make here are not on a branch unless you create one.

COMMAND RUN > git switch --detach c3d4e5f a1b2c3d b2c3d4e c3d4e5f d4e5f6g e5f6g7h HEAD main Detached HEAD means HEAD points directly to a commit instead of to a branch label. COMMAND RUN > git commit -m "temp fix in detached HEAD" a1b2c3d b2c3d4e c3d4e5f d4e5f6g e5f6g7h f1a2b3c HEAD main A commit made in detached HEAD is not on a branch. If you switch away without creating a branch, that commit can become orphaned. Git usually keeps unreachable reflog entries for 30 days, and unreachable loose objects may be pruned after about 2 weeks when garbage collection runs.
git switch --detach c3d4e5f
git switch -c inspect/old-release
Previous Branches All Concepts Back To Overview Next Working Tree + Staging