Course contentsShow
← Computer Science
Lesson 2184 of 2,87249. Version Control with GitFree lesson

The HEAD Pointer

Understand what HEAD represents in Git and how it tracks your current position in the repository's commit history.

The HEAD Pointer

You'll learn what HEAD is in Git and how it keeps track of where you are in your repository's history.

What is HEAD?

In Git, HEAD is a special pointer that tells you where you currently are in your repository's commit history. Think of it like a bookmark that marks your current position in a book—it shows you which commit you're looking at right now and which branch you're working on.

Most of the time, HEAD points to the tip of a branch (the most recent commit on that branch). When you switch branches, HEAD moves to point to the tip of the new branch. This is how Git knows what content to show in your working directory.

HEAD as Your "You Are Here" Marker

Imagine your commit history as a map with multiple paths (branches). HEAD is the "You Are Here" marker. When you:

  • Create a new commit: HEAD moves forward to point to the new commit
  • Switch branches: HEAD moves to point to the latest commit on that branch
  • Check out an old commit: HEAD can point directly to that specific commit (called "detached HEAD")

You can see where HEAD is pointing by running git log or checking the output of git status. When you see references like HEAD, HEAD~1 (one commit before HEAD), or HEAD~2 (two commits before HEAD), they're all relative to this pointer's current position.

Key Takeaway: HEAD is Git's pointer to your current position in the repository—usually the latest commit on your active branch—and it moves automatically as you commit, switch branches, or navigate history.