4
>git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Are they both same, if yes then why do we have two.

Karun
  • 447
  • 5
  • 17

2 Answers2

5

If master is checked out, then HEAD is master. That is not the case if another branch (or simply a commit) is checked out - as HEAD is a reference to the current commit you're on.

Example:

git checkout wip
# Then HEAD == wip

git checkout aed24d
# Then HEAD == aed24d
Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
0

HEAD is a comvenience. It's a helper/shortcut.
It's frequently pointed at origin/master but it can also point to another branches commit.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497