Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is HEAD in Git?

Tags:

git

You see the Git documentation saying things like

The branch must be fully merged in HEAD.

But what is Git HEAD exactly?

like image 972
bobobobo Avatar asked Feb 20 '10 22:02

bobobobo


People also ask

What is head and head git?

HEAD^ means the first immediate parent of the tip of the current branch. HEAD^ is short for HEAD^1 , and you can also address HEAD^2 and so on as appropriate. The same section of the git rev-parse documentation defines it as. <rev>^ , e.g. HEAD^ , v1.5.1^0.

What is origin and head in git?

What is Origin (or Remote Head) in Git? The word origin is an alias that Git created to replace the remote URL of a remote repository. It represents the default branch on a remote and is a local ref representing a local copy of the HEAD in the remote repository.

Where is the head in git?

In Git, a head is a ref that points to the tip (latest commit) of a branch. You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.

What is the head of a repo?

Head: Head is the repository containing the changes that will be added to the base. Following the example above, this is your repository (your fork of your colleague's repo).


1 Answers

You can think of the HEAD as the "current branch". When you switch branches with git checkout, the HEAD revision changes to point to the tip of the new branch.

You can see what HEAD points to by doing:

cat .git/HEAD 

In my case, the output is:

$ cat .git/HEAD ref: refs/heads/master 

It is possible for HEAD to refer to a specific revision that is not associated with a branch name. This situation is called a detached HEAD.

like image 141
Greg Hewgill Avatar answered Oct 19 '22 09:10

Greg Hewgill