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
  • 397
  • 4
  • 15

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
  • 40,550
  • 15
  • 92
  • 129
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
  • 89,394
  • 88
  • 305
  • 468