What is HEAD in Git?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Git & GitHub basics — a prerequisite for any developer role.
Answer
HEAD is a special pointer in Git that refers to the currently checked-out commit — the commit your working directory is based on. Normally, HEAD points to a branch name (like main), which in turn points to the latest commit on that branch. This is called "attached HEAD." When you make a commit, the branch pointer advances and HEAD follows. HEAD references: HEAD — current commit; HEAD~1 or HEAD^ — parent commit (one before current); HEAD~3 — 3 commits back; HEAD^^ — grandparent. Detached HEAD state: when you checkout a specific commit hash or tag instead of a branch (git checkout abc1234), HEAD points directly to that commit rather than a branch. You can look around and make experimental commits, but those commits won't belong to any branch and may be lost if you switch away. To save work in detached HEAD: git checkout -b new-branch — creates a branch at the current commit. The .git/HEAD file contains the current HEAD value — either a branch reference (ref: refs/heads/main) or a raw commit hash (detached).
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.