0

I wonder, is not HEAD is the current branch? As far as I'm concerned it is. But this shows that this is not the case:

$ git branch
* develop
  master

So the current branch is develop. But HEAD is not:

 $ git branch -r
  origin/HEAD -> origin/master
  origin/develop
  origin/master
Incerteza
  • 32,326
  • 47
  • 154
  • 261
  • This is a question that gets asked a lot on Stack Overflow, but I haven't been able to find a good canonical for it yet. When I find one, I'll have to mark this as a duplicate. –  Jun 12 '14 at 04:52
  • Related (or duplicate): [How does origin/HEAD get set?](http://stackoverflow.com/q/8839958/456814). –  Jun 12 '14 at 04:53
  • Related (or duplicate): [Git branch named origin/HEAD -> origin/master](http://stackoverflow.com/q/4359099/456814). –  Jun 12 '14 at 04:55
  • Related: [What is the use of the origin/HEAD branch?](http://stackoverflow.com/q/8223406/456814). –  Jun 12 '14 at 04:55
  • Possible duplicate of [What is the use of the origin/HEAD branch?](https://stackoverflow.com/questions/8223406/what-is-the-use-of-the-origin-head-branch) – Cœur Jul 14 '18 at 11:48

2 Answers2

1

You use the -r option, so it lists the remote-tracking branches.

  origin/HEAD -> origin/master

means the HEAD in the remote refs the HEAD of remote branch origin/master.

xdazz
  • 158,678
  • 38
  • 247
  • 274
1

HEAD in your local repository references the currently checked-out commit, which may or may not also be the location of a branch. So HEAD in a local repository does not always refer to the currently checked-out branch. For example, you can enter a "detached HEAD" state by checking out a commit directly.

However, in the context of remote repositories, HEAD refers to the default branch for that remote. So

origin/HEAD -> origin/master

means that the default branch on origin is the master branch.

  • http://stackoverflow.com/a/8223893/2813589 - says it points to the current branch in local, whereas you said `So HEAD in a local repository does not always refer to the currently checked-out branch.`. How is that? – Incerteza Jun 12 '14 at 05:05
  • 1
    @AlexanderSupertramp simple, **that other answer is wrong**. –  Jun 12 '14 at 05:08
  • Then I don't understand. Does HEAD refer to a branch or commit? – Incerteza Jun 12 '14 at 05:50
  • @AlexanderSupertramp in a non-bare local repository, it refers to the current commit. In the case of your remote origin, it refers to the default branch, ***on the origin remote***. I think the default branch thing applies to bare repositories in general, but I need to double check that. –  Jun 12 '14 at 05:52
  • @AlexanderSupertramp also note that although [the documentation itself](https://www.kernel.org/pub/software/scm/git/docs/git.html) says that HEAD refers to the current branch, that isn't quite correct, the documentation is misleading `:P`. –  Jun 12 '14 at 05:53