19

I recently merged a branch I was working on with the 'master' branch. I must have (still kind of a git n00b) done something when pushing or pulling that created both an origin/master and an origin/HEAD branches. Unfortunately, I didn't keep a record of what commands I ran that did this. Currently, my team has a bunch of code in their master copies that I'm not getting when I check out the project (even if I clone to a new location).

Here's a screenshot of what Sourcetree is showing:

2 branches

I really need to get this resolved so I can keep working so any help will be greatly appreciated.

Community
  • 1
  • 1
Zachary Abresch
  • 756
  • 3
  • 8
  • 20
  • That's not something you need to worry about. I also have it in some of my repositories, but it's something like, just a pointer to `origin/master`. If you do `git branch -r`, you should see this. – Shahbaz Jul 17 '12 at 17:03
  • Hmmm ... any ideas on why my master is so out of sync with the ones my teammates have? – Zachary Abresch Jul 17 '12 at 17:05
  • Well of course, since you have different repositories, you need to bring them in sync. So, is your question actually "how to merge _your_ work with that of `origin`"? – Shahbaz Jul 17 '12 at 17:10

2 Answers2

16

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):

  1. navigate to your repository
  2. execute: git remote set-head origin -d

now it should be gone:

$ git branch -r
origin/master
Gabriel
  • 593
  • 5
  • 13
8

The branches you see that begin with origin/ are so-called "remote-tracking braches". They tell you the position of the branches in the repository origin the last time git fetched from that repository.

It's nothing to worry about - this is actually helpful information. If you think those branch positions are out of date, you can run:

git fetch origin

... to update them.

In any repository, HEAD is special kind of ref (a "symref") that represents the current branch (or current commit, if you're not on a particular branch).


You can see in the diagram that your master branch is actually one commit ahead of origin/master, so if your colleagues have been pushing to master in origin and you ran git fetch origin (or something equivalent) recently, you already have all their work. However, they will be missing out on your commit until you push that.

You say:

Currently, my team has a bunch of code in their master copies that I'm not getting when I check out the project (even if I clone to a new location).

If that's the case, they're probably pushing to a different branch, a different repository, or they haven't pushed their work at all.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Also `git merge origin/` to merge `` with your currently checked out branch. That way, not only you update your copy of `origin`'s branches, but you actually get the changes in your local ones. – Shahbaz Jul 17 '12 at 17:22
  • 1
    I didn't mention that because in the OP's situation merging `origin/master` won't do anything - his `master` is *ahead* of `origin/master`. – Mark Longair Jul 17 '12 at 20:10
  • Yes, I just said it to make the answer more complete. Since he says "Currently, my team has a bunch of code in their master copies that I'm not getting when I check out the project", you told him to `git fetch`, I mentioned that following that, he should `git merge`. – Shahbaz Jul 17 '12 at 22:34