Julia Evans

How HEAD works in git

The author of the article ran a poll on Mastodon asking people how confident they were in their understanding of how HEAD works in Git, and the results showed that many people were uncertain or had no idea. The author initially thought HEAD was a straightforward topic but discovered that it was more complicated than they appreciated after having follow-up conversations with others. HEAD can refer to different things, including the file .git/HEAD, the "revision parameter" HEAD in commands like git show HEAD, and the various ways HEAD is used in Git's output. The file .git/HEAD contains either the name of a branch or a commit ID and determines the current branch in Git. If .git/HEAD contains a commit ID, Git calls that "detached HEAD state," which means there is no current branch. In detached HEAD state, new commits will not be attached to any branch and can be difficult to find or may be deleted by Git's garbage collection. The author explains how to interpret the output of various Git commands that use HEAD, including git status, git log, and merge conflicts. They also suggest that Git's terminology around HEAD could be more consistent and intuitive.
favicon
jvns.ca
jvns.ca
Create attached notes ...