What is HEAD in Git?

HEAD is a special pointer which tells Git where you are now. Usually it points to the current branch, and that branch points to its latest commit. When you make a new commit, the branch and HEAD move forward.

Terminal output

$ git log –oneline
f411fbd (HEAD -> main) Second
0057196 First
$ git show –oneline –no-patch HEAD~1
0057196 First

  • HEAD is the current commit.
  • HEAD~1 (or HEAD^) is its parent, HEAD~2 is two commits back.
  • If HEAD points to a commit and not a branch, it is called a detached HEAD.

Learn more about the similar topics:
Tutorials
Git Init
Git Status
Git Add
Git Commit
Git Log
Git Diff
Git Ignore (.gitignore)
Exercises & Assignments
Check the status of files in a Git repository
Stage only selected files and commit them separately
Show the commit history in one line per commit
See the changes of a file before staging and before commit
Ignore all .log files with .gitignore
Unstage a file
Delete a file with git rm
Interview Questions & Answers
How can you add files to Git?
How can you commit a file in Git?
What are the common files to ignore in Git?
How to remove untracked files in Git?
What is the staging area in Git?
What is the difference between git add and git commit?
What is HEAD in Git?