1

I have Git configurations for participants in a project that are designed to behave the same for me and for all collaborators. So that, for example, our branch names match and the branches track the same remote.

On my end I begin with a Git repo that contains my project and I execute (1)

git checkout -b dev
git remote add development <dev-repo uri>
git push --set-upstream development dev

to create and configure the branches and remote repos that we will use to collaborate. Then I simply instruct my collaborators to (2)

git clone -o development <dev-repo uri>

Everything works as expected. In particular, the local repos "look" pretty much identical (which aids communication) — except for one difference: the second configuration, (2), has an additional on branch the remote: development/HEAD. What is this branch and where did it come from? Why is it not present in (1). Does its presence (or absence) have any effect?

orome
  • 45,163
  • 57
  • 202
  • 418
  • As near as I can tell, `development/HEAD` seems merely to be a synonym for `development/dev`; `git branch -a -v` for example, shows `remotes/development/HEAD -> development/dev`)? – orome Jan 29 '13 at 21:43
  • http://stackoverflow.com/questions/12613793/why-is-there-a-remotes-origin-head-origin-master-entry-in-my-git-branch-l?lq=1 – ellotheth Jan 29 '13 at 22:37
  • @ellotheth: So it will **always** just be an alias for `development/dev`? – orome Jan 29 '13 at 22:57
  • 2
    It will always be an alias for whatever the remote defines as the 'default' checkout branch. – ellotheth Jan 29 '13 at 23:12

2 Answers2

2

The first part of your question is a dupe.

Here's my guess for the second part: When you clone a repo, you're building a complete repository, including the working directory, from scratch. Without a remote HEAD, git has no idea which branch to check out initially--stated another way, git doesn't know what your local HEAD should be, it doesn't know where to get the files for your working directory.

On the other hand, when you add a remote to an existing repo, you're adding to something that's already complete. Git doesn't have to care which branch the remote would check out by default. You've already got a local HEAD, so you don't need guidance from the remote.

Community
  • 1
  • 1
ellotheth
  • 4,333
  • 2
  • 17
  • 29
  • I asume then that `git branch -d -r development/HEAD` will have no consequence other than to tidy up my list of branches. – orome Feb 01 '13 at 21:53
1

HEAD is not really a branch it's a symbolic ref. On the remote it represents its actual branch. You can check what it is with git symbolic-ref refs/remotes/development/HEAD or just simply view the file .git/refs/remotes/development/HEAD.

When you clone a repository then (by default) that branch will be checked out in your local repository to which the HEAD ref points to on the remote, unless master is on that commit too, because then the master branch is checked out, it has higher priority somehow, at least this was the case a year ago.

Why it exists in your repository and not in the other one? I don't know, but it doesn't really matter.

tewe
  • 2,707
  • 3
  • 22
  • 18