2

When I do this:

git branch -a

I see precisely this:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Do I have two remote branches? How did I get in this situation?

All I have is my local directory, MyProject, and my remote branch on the server, MyProject.git. Other projects on my PC just have master and remotes/origin/master. Where did this HEAD branch come from?

Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • Different branches are denoted by asterisks, so your only branch is `* master`. I think `remotes/origin/HEAD` points to the currently used branch, which is `origin/master/`, your only branch. But that's my interpretation... – Blender Apr 04 '11 at 03:19
  • 3
    @Blender, no, the asterisk indicates the branch you currently have checked out. "the current branch will be highlighted with an asterisk" http://www.kernel.org/pub/software/scm/git/docs/git-branch.html – Joe White Apr 04 '11 at 03:25

1 Answers1

4

You only have one local branch and one remote branch.

  • master is a reference to your local branch, and the * means it is the currently checked-out branch.

  • remotes/origin/HEAD is the HEAD reference of the remote repository named origin, it is simply a pointer to the master branch in the origin remote repository.

  • remotes/origin/master is the reference to the master branch on the remote repository named origin.

The last two exist so that Git can keep track of where the remote repository is (or was at the last git fetch).

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
  • Then why don't my other projects look like this? The others don't have that HEAD line. – Ryan Lundy Apr 04 '11 at 05:05
  • 1
    @Kyralessa: Git is a little funky about its remote HEAD detection. Not all operations fetch it, and it's only fetched by SHA1, not as a symref, so Git has to infer from that hash what branch it's probably pointing to. I believe the exact behavior has changed through various versions, too - so if you cloned one repo with one version, and another with another, you might've fetched `HEAD` in one but not the other? You can try `git remote show origin` - it should show something like "HEAD branch: master", and might refresh things. – Cascabel Apr 04 '11 at 13:45
  • Kyraless, your other repositories may be bare. See http://stackoverflow.com/questions/5540883/whats-the-practical-difference-between-a-bare-and-non-bare-repository/5541917#5541917. – Derek Mahar Apr 04 '11 at 18:48
  • @Derek that answer has nothing to do with the state of the remote branch. – Andrew Marshall Apr 04 '11 at 19:37
  • Andrew, Kyralessa said that her other projects "don't have that HEAD line" which I guessed means they don't have the remote origin. This may be because they don't have any remote repositories or may be bare. – Derek Mahar Apr 04 '11 at 20:11