What Is HEAD in Git?

Find out what "HEAD" refers to in git

In git, HEAD is like a pointer that points to the local branch you're currently on. If, for example, you switch to a different branch, then HEAD would point to that branch. Internally, git keeps a reference of the "current" branch in .git/HEAD file (which you can see if you print the contents of it):

cat .git/HEAD

For example, if you're on the main branch, then it would output the following:

ref: refs/heads/main

If, for example, you switch to a branch called "foo", then the HEAD would point to the branch ref of that branch:

git switch foo

cat .git/HEAD

# output: ref: refs/heads/foo

Please note that when you switch to a certain commit, tag or remote branch, then the HEAD would be in a "detached" state.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.