Difference between HEAD and master
What is the difference between the HEAD
and master
in Git?
I did a clone of a project on GitHub and want to push my changes to the remote. But to which one should I push?
master
is a reference to the end of a branch. By convention (and by default) this is usually the main integration branch, but it doesn't have to be.
HEAD
is actually a special type of reference that points to another reference. It may point to master
or it may not (it will point to whichever branch is currently checked out). If you know you want to be committing to the master
branch then push to this.
Here is a visual example:
On your own repository you can check where the HEAD
is pointing to by running this:
$ git symbolic-ref HEAD
refs/heads/master
However, finding out where the remotes/origin/HEAD
is pointing to is more tricky because it is on the remote machine.
There is a great little tutorial on git references here:
http://people.gnome.org/~federico/news-2008-11.html#pushing-and-pulling-with-git-1
The simple answer is that HEAD
is a pointer/label to the most recent commit of the branch you are currently on. master
is the default branch created when you initialized a git repository (e.g. git init
).
You can delete the master
branch (e.g. git branch -D master
). You cannot delete the HEAD
pointer.