2

I am having some strange problem with my GIT repository. I have two branches, 'master' and 'staging'. I usually work on 'staging' and the owner of the project works on 'master'. So what I do with master is usually just switch to it (git checkout master) to it, pull the changes, then switch back to staging and merge the master with staging. Basically, I don't make any updates to the master branch. Now can any body explain the problem in this image:

alt text

How comes my 'master' is beyond 'remotes/origin/master' while I take the commits from 'remotes/origin/master'?!! And how is it possible to make 'master' and 'remotes/origin/master' both points to the last commit?

UPDATE: To answer Jefromi's questions in the first comment, I want to add: The 5 commits all come from the other developer working on the master branch. That is, when I did "git pull origin master" (while on the master branch), I got those additional 5 commits and the 'master' label moved to the last commit, but not the 'remotes/origin/master'. Now, whenever I switch to the master branch, I get this message:

"Your branch is ahead of 'origin/master' by 5 commits."

Rafid
  • 18,991
  • 23
  • 72
  • 108
  • 1
    This sounds like a question only you can answer. Where did those five commits come from? If you created them, maybe you had master checked out instead of staging. If they're from origin, maybe you pulled something besides origin/master, or maybe origin/master got moved forward then back again (though that's bad, because it causes this kind of confusion, and more). – Cascabel Dec 12 '10 at 08:00
  • I added some updates to the question to answer your questions. – Rafid Dec 12 '10 at 08:21
  • 1
    Is that the correct position of origin/master? Examine the remote directly, if you can. Does `git ls-remote origin` show the SHA1 of that commit for origin/master? What happens if you run `git fetch origin`? – Cascabel Dec 12 '10 at 14:12
  • @Jofromi, "git fetch origin" solved the problem! Thank you very much, but I don't understand why?!! I used to do "git pull origin " and as far as I understood, the pull is actually a fetch+merge, so I never thought of using "git fetch". It seems that "fetch" does actually do "fetch+merge" but do that on the fly, so it doesn't update the remotes/origin/! What do you say? – Rafid Dec 19 '10 at 19:53

1 Answers1

1

I had a similar question, see here:

git: setting a single tracking remote from a public repo

You could try:

$ git pull  # with no mention of origin or master

If that does not work, try setting up the branch as described at the bottom of the original post linked above.

I have a feeling of this having changed in different quite recent versions of git, you should say what version you are using.

Community
  • 1
  • 1
Gauthier
  • 40,309
  • 11
  • 63
  • 97