Git & GitHub Interview Question #21

What is HEAD in Git?

Git Fundamentals, Repository, Working Tree, Staging, Commits & Branch Basics Junior Beginner

Quick Interview Answer

HEAD is Git's reference to the currently checked-out position. In normal branch-based work, HEAD points to the current branch, which in turn points to the latest commit on that branch.

Detailed Explanation

HEAD is Git's reference to the currently checked-out position. In normal branch-based work, HEAD points to the current branch, which in turn points to the latest commit on that branch.

When you make a new commit, the current branch reference normally moves forward and HEAD continues to refer to that branch. HEAD can also point directly to a commit in a detached HEAD state.

Code Example

git status
git log -1 --oneline

git show HEAD