HEAD
Git's pointer to where you are: normally the name of the current branch, and through it the current commit.
In more detail
The file .git/HEAD usually contains a line such as ref: refs/heads/main. Committing follows HEAD to find which branch to move; switching branches rewrites HEAD. Most commands assume HEAD when you name no commit, and HEAD~1 means the commit before it.
Examples
cat .git/HEADgit rev-parse HEADRelated terms
- branch — In Git, a movable name for one commit; committing on the branch moves the name forward to the new commit.
- detached HEAD — The state where HEAD holds a commit ID directly instead of a branch name, so new commits are made but no branch moves to follow them.
- symbolic ref — A ref that holds the name of another ref instead of an object ID, as HEAD normally holds the name of a branch.
- ancestry reference — A way of naming a commit by counting back from another: a tilde and a number walk back that many first parents, and a caret picks which parent.
Taught in
- Recovering And Removing Data With Git — Microsoft Azure DevOps Engineer Expert (AZ-400) Exam Prep
- Half The Marks Are Definitions: How The Exam Works — Certified GitOps Associate (CGOA) Exam Prep
- Staging Is Gone: Desired State, Declarations And The State Store — Certified GitOps Associate (CGOA) Exam Prep
- Two Ways Back From 2.5: Rollback The GitOps Way — Certified GitOps Associate (CGOA) Exam Prep
- Terminology Sprint: One Incident, Nine Terms — Certified GitOps Associate (CGOA) Exam Prep
- Someone Cleaned Up The History: Versioned And Immutable — Certified GitOps Associate (CGOA) Exam Prep
- Principles Sprint: Six Setups, One Question — Certified GitOps Associate (CGOA) Exam Prep
- Related Practices Sprint: One Change, Five Practices — Certified GitOps Associate (CGOA) Exam Prep
- Three Teams, Three Formats: Manifests And Packaging — Certified GitOps Associate (CGOA) Exam Prep
- DevOps Sprint: Tax At A Hundred Percent — CompTIA Cloud+ (CV0-004) Exam Prep
- Security Baselines, Policies & Hardening Standards — Cybersecurity Fundamentals, GRC & Cryptography
- A Repository Is A Folder With A Memory — Advanced Git Internals & Distributed Workflows
- What A Commit Really Is — Advanced Git Internals & Distributed Workflows
- The Three Areas: Working Tree, Index, Repository — Advanced Git Internals & Distributed Workflows
- Committing, And What A Good Message Says — Advanced Git Internals & Distributed Workflows
- Reading History: log, show And diff — Advanced Git Internals & Distributed Workflows
- Ignoring Files, And The Tracked File Trap — Advanced Git Internals & Distributed Workflows
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- HEAD, And Why Detached HEAD Is Not An Error — Advanced Git Internals & Distributed Workflows
- Merging: Fast Forward Or A Merge Commit — Advanced Git Internals & Distributed Workflows
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows
- Undoing: restore, reset, revert And stash — Advanced Git Internals & Distributed Workflows
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- Resolving A Conflict, Line By Line — Advanced Git Internals & Distributed Workflows
- Interactive Rebase: Squash, Reorder, Reword — Advanced Git Internals & Distributed Workflows
- Cherry Picking, Reflog, And Getting Work Back — Advanced Git Internals & Distributed Workflows
- Investigating History: blame, bisect And worktree — Advanced Git Internals & Distributed Workflows
- The Release Tag That Never Left The Laptop: Git Branches, Remotes, Tags And History — CompTIA Linux+ (XK0-006) Exam Prep
- Git And VS Code: Clone, Commit, Push, And The Dev Container — RHCE in Ansible (EX294): Automate Red Hat Systems
References
Certification courses
- AZ-400 course and practice exam: Microsoft Azure DevOps Engineer Expert
- CGOA course and practice exam: Certified GitOps Associate
- CompTIA Cloud+ course and practice exam: CV0-004
- CompTIA Linux+ course and practice exam: XK0-006
- RHCE course and practice exam: Red Hat Certified Engineer in Ansible (EX294)