Video in progress
What is HEAD in Git?
HEAD is a special pointer that shows which commit you are on right now. Usually it points to a branch (for example main), and the branch in turn points to the latest commit.
📖 Answer
cat .git/HEAD
# ref: refs/heads/main
So HEAD -> main -> commit a1b2c3. When you make a new commit, main moves forward, and HEAD still points to main.
References relative to HEAD are common in commands:
HEAD~1: the parent of the current commit;HEAD~3: three steps back;git diff HEAD: the state on disk compared with the last commit.
If HEAD points straight at a commit instead of a branch, that is called a "detached HEAD" state. It happens, for example, when you run git checkout a1b2c3.
Sign up to mark studied questions and save your progress.