Getting Started Git Basics History and HEAD
History and HEAD
Understand Git history, HEAD, and how your current branch or commit relates to the commit graph.
Git history is the chain of commits for a repository, and HEAD refers to your current position in that history.
These two ideas are fundamental in Git because almost every action involves either moving through history or adding new commits to it.
What Git history is
Git history is the record of the commits saved in a repository over time.
Each commit points to an earlier commit, which creates a chain. When branches are involved, the history is better understood as a graph rather than one simple straight line, but it is still helpful for beginners to think of it as a sequence of saved project states.
History helps you:
- See what changed over time.
- Understand when a change was introduced.
- Compare older and newer versions of the project.
- Move back to an earlier commit if needed.
What HEAD means
HEAD is Git's name for your current position in the repository history.
Most of the time, HEAD points to the branch you currently have checked out. That means new commits are added to that branch, and HEAD moves forward with it.
For example:
A --- B --- C main
^
HEADIn this example, HEAD is on main, and main points to commit C.
HEAD and the current branch
When you switch branches, HEAD moves to the branch you checked out.
Before switching:
A --- B --- C main
\
D --- E feature
^
HEAD
After switching to main:
A --- B --- C main
^
HEAD
\
D --- E featureThat is why changing branches can change:
- Which commit you are looking at.
- Which files appear in the worktree.
- Which branch new commits will extend.
This is also why HEAD is often described as "where you currently are" in the repository.
Detached HEAD
Sometimes HEAD points directly to a commit instead of a branch. This is called a detached HEAD state.
That can happen if you check out a specific commit rather than a branch tip.
Detached HEAD is not automatically wrong or dangerous, but it does mean new commits you make there are not attached to a normal branch name unless you create one.
History and HEAD in GitComet
GitComet helps you see both the repository history and your current place in it.
That includes:
- The list or graph of commits.
- The current branch.
- The commit currently checked out.
- How your local branch relates to remote branches.
When you understand history and HEAD, many other Git actions become easier to reason about, especially switching branches, rebasing, and resolving conflicts.