git,

Git HEAD vs head vs tip vs origin

Sep 25, 2022 · 2 mins read · Post a comment

Here’s few other core concepts around Git: HEAD, head, tip and origin. I’m going to break them down briefly as I did previously with the rest of the related posts shared at the end of this one.

Refs and references are used interchangeably.

Prerequisites

  • Git

Solution

Let’s start with HEAD. What is HEAD exactly?

Simply put HEAD is a pointer to the latest commit in your current branch of the repository. It points to whatever your repo is currently pointing at. There is only one HEAD. HEAD follows you. It moves to whatever branch and commit you are checking out. Supposing that you have checked out a commit instead of branch, HEAD will be also known as a detached head. To be clear, when checking out to a certain branch you are actually pointing to the latest commit of that branch. To check where it points to, use:

cat .git/HEAD

Output:

ref: refs/heads/main

As we could see it points to refs/heads/main which is the main branch. To be precise HEAD mostly points to a branch reference. Also, if you want to see the actual commit you could use:

git show
git show @
git show HEAD

Keep in mind HEAD is not the same as head. So, what is head?

You can also think of it as a reference to the tip of a branch. One head per branch. Following the example above, let’s find out where this head points to.

cat .git/refs/heads/main

Output:

7ba80b2050da1b897fe8i3c5f6f22wf34bd51t75

It points and outputs the commit SHA1 of the main branch. Think of it as: HEAD -> refs/heads/main -> <commit-SHA1>. To list all refs, run: ls -l .git/refs/heads.

Now, what is tip? Tip is the latest commit on a branch. One tip per branch as well.

Finally, origin is the default local name of the remote repository (also known as remotes) that you have cloned your project from. It points to the remote repository URL. To list Git remotes, run:

git remote -v

This should get you going down into the Git’s rabbit hole.

Conclusion

Related posts:

To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.

git