Git branch named origin/HEAD -> origin/master
GitGit Problem Overview
I'm fairly new to Git, and still getting the hang of it. I just recently started working with branches and am running into some questions.
I have two development systems, an Ubuntu desktop and an MacBookPro. I did a bunch of work in a new organizations
branch on the Ubuntu system and performed commits and pushed to my remote repo. At this point, I had these branches:
tauren@ubuntu:/projects$ git branch
accounting
master
* organizations
tauren@ubuntu:/projects$ git branch -r
origin/accounting
origin/master
origin/organizations
origin/superstar
Then I switched to the MBP to pull the new branch:
tauren@osx:/projects$ git branch
accounting
* master
tauren@osx:/projects$ git branch -r
origin/HEAD -> origin/master
origin/accounting
origin/master
origin/superstar
tauren@osx:/projects$ git pull
2e20a14..ef35730 accounting -> origin/accounting
271a1a5..7e947ab master -> origin/master
* [new branch] organizations -> origin/organizations
tauren@osx:/projects$ git branch
* accounting
master
tauren@osx:/projects$ git branch -r
origin/HEAD -> origin/master
origin/accounting
origin/master
origin/organizations
origin/superstar
So my questions are these:
- Why does the MBP have a branch
origin/HEAD -> origin/master
, but the Ubuntu system doesn't? What is that branch? - Does
git pull
automatically pull all new remote branches? I thought I had to tell it the name of new branches to pull. As you can see, it pulled the remoteorganizations
branch on the commmandgit pull
.
Git Solutions
Solution 1 - Git
HEAD
usually points to the currently checked out branch. In hosted (bare) repositories, it designates the default branch, i.e. the branch that is checked out when you clone the repository. So, origin/HEAD tells you the default branch of origin.
I don't know why it's not present in your repository on the Ubuntu system. Perhaps you originally pushed your code from that repository (when origin was empty and thus didn't have a HEAD yet) and never updated it.
Having something like origin/HEAD is not terribly important in practice, anyway. If you want, you can use git remote set-head origin -a
to have origin/HEAD
created/updated
To answer your other question: if you run git pull
without arguments, it actually fetches everything from the remote (git fetch
is run without arguments, too, so it just gets everything). Everything doesn't get merged, though. Only the remote-tracking branches (the stuff in git branch -r
) are updated.
Solution 2 - Git
As far as I know, HEAD
is not a branch, but rather a pointer to a node of the history tree (i.e. a commit). The files which are residing in you particular working copy have the state described by HEAD
.
Usually HEAD
points to the most recent commit in a branch, so you have the most recent files in the working copy. Using git reset HEAD^
you can shift the pointer to previous commit (i.e. undoing the last commit in your local copy).
Now, every git repo has a HEAD
, check this with git show HEAD
. Accordingly, origin/HEAD
is HEAD
of your origin
remote.
Now, I've found a good question describing HEAD
: https://stackoverflow.com/questions/2304087/what-is-git-head-exactly
Solution 3 - Git
It is just a pointer to master, a symbolic link if you wish. You can safely delete it by doing the following in a terminal (or git bash/cygwin for windows users):
- navigate to your repository
- execute:
git remote set-head origin -d
now it should be gone:
$ git branch -r
origin/master