Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git branch named origin/HEAD -> origin/master

Tags:

git

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:

  1. Why does the MBP have a branch origin/HEAD -> origin/master, but the Ubuntu system doesn't? What is that branch?
  2. 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 remote organizations branch on the commmand git pull.
like image 762
Tauren Avatar asked Dec 05 '10 13:12

Tauren


People also ask

What does head -> Master mean in git?

HEAD really just means "what is my repo currently pointing at". In the event that the commit HEAD refers to is not the tip of any branch, this is called a "detached head". master: the name of the default branch that git creates for you when first creating a repo. In most cases, "master" means "the main branch".

What is Origin head and origin master in 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.

What is the difference between origin head and origin master?

The simple answer is that HEAD is a pointer/label to the most recent commit of the branch you are currently on. master is the default branch created when you initialized a git repository (e.g. git init ). You can delete the master branch (e.g. git branch -D master ). You cannot delete the HEAD pointer.

How do I point my head to the origin master?

the HEAD is not stepping onto any branch, then above commands do: checkout the target commit (you're already stepping there, but just in case) move master pointer to that commit (no problem, since it is a forward move) checkout master branch in order to be stepping onto it (for future commits)


1 Answers

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.

like image 82
Jan Krüger Avatar answered Oct 18 '22 19:10

Jan Krüger