1

Possible Duplicate:
HEAD and ORIG_HEAD in Git

By default we see two branches in git:

origin/master
origin/HEAD

I wonder, what is head used for?

Community
  • 1
  • 1
Elisa
  • 6,865
  • 11
  • 41
  • 56
  • The Git Community book says that it is a pointer to your current branch. Source: http://book.git-scm.com/1_git_directory_and_working_directory.html – 0x1F602 Nov 22 '11 at 07:36
  • http://stackoverflow.com/questions/964876/head-and-orig-head-in-git – Timofey Stolbov Nov 22 '11 at 07:37
  • This question shouldn't have been closed as a duplicate of [HEAD and ORIG_HEAD in Git](http://stackoverflow.com/q/964876/456814), this deals with `HEAD` in remotes, not a local repository. –  Jun 12 '14 at 04:47
  • Possible duplicate of [HEAD doesn't point to the current branch?](http://stackoverflow.com/q/24176052/456814). –  Jun 12 '14 at 04:59
  • Possible duplicate of [HEAD and ORIG\_HEAD in Git](https://stackoverflow.com/questions/964876/head-and-orig-head-in-git) – Cœur Jul 14 '18 at 11:49

2 Answers2

1

It's a pointer to the current commit.

Since it represents a commit you can can use it with most of git's commands.

Examples:

Show the latest commit with it's diff:

git show HEAD

Interactively rebase to the commit before the latest:

git rebase -i HEAD^
ghickman
  • 5,893
  • 9
  • 42
  • 51
  • HEAD ***does not*** refer to your current ***branch***, it refers to the currently checked-out commit. You can check-out a commit directly, which puts you in a "detached HEAD" state (detached from a branch). If you checkout `HEAD~10` for example, HEAD will then refer to a commit that's 10 commits behind your previous branch. –  Jun 12 '14 at 04:58
  • Thanks @Cupcake, I've updated my answer appropriately. – ghickman Jun 12 '14 at 09:01
1

HEAD is a a symbolic reference (similar to a symbolic link) that points to the branch you're on. You can get the reference it points to using git symbolic-ref HEAD. If you switch branches (e.g. git checkout branch1), HEAD will point to that. This is stored in a file in .git as .git/HEAD.

master is a local branch that you can work on. It's usually the default if you clone a repository or start a fresh one.

origin/master is the location of the master branch on the remote called origin.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • 2
    HEAD in a local repository does not always refer to a branch, it more specifically refers to the currently checked-out branch. You can enter a detached HEAD state where HEAD no longer refers to any branch. –  Jun 12 '14 at 05:10
  • Correct. I didn't mention that because it's not *that* common and the OP's question suggested her lack of experience with git. – Noufal Ibrahim Jun 12 '14 at 05:45
  • It's funny though, even [the documentation itself](https://www.kernel.org/pub/software/scm/git/docs/git.html) says that HEAD refers to the current branch. The documentation is wrong `:/`. –  Jun 12 '14 at 05:50
  • That is in some ways true. Even in a detached head state, you are somewhere and that can be referred to as a head (which is what git says for branch) but yeah, you're right. Send them a pull request? – Noufal Ibrahim Jun 12 '14 at 06:19