5

When I clone a remote repository with

  1. git clone 'repo_url'
  2. git pull
  3. git status

I get this message -

On branch master
Your branch and 'origin/master' have diverged,
and have 41 and 20 different commits each, respectively

When I use git pull -a I do not have this issue.

Are things out of sync on the remote repo? with the HEAD and the master ? How do I fix it?

EDIT 1 :

when I run git branch -a : this is what it looks like...

$ git branch -a

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/clothes
  remotes/origin/dunnesBranch
  remotes/origin/master

EDIT 2 :

It seems to me that origin/master is not pointing to the latest code... I ran 'git clone ' then git reset --hard origin/master and then a 'git pull' and it attempted a merge which failed due to conflicts...

I think... The HEAD of the remote repo is pointing to the latest commit, origin/master is pointing to a different, older commit... I can verify this when I run git show...

user2283043
  • 83
  • 1
  • 7

2 Answers2

7

Not sure about the cause, unless:

  • there is a git push --force on origin by someone else, done between you cloning the repo, and you pulling that same repo
  • the fetch refspec (git config --get remote.origin.fetch) isn't +refs/heads/*:refs/remotes/origin/*.

But you can reset master easily enough:

git reset --hard origin/master

Make sure master is tracking origin/master:

git branch -u origin/master master

And make sure your push policy is 'simple' (in order to push the current branch out to the same name at the remote repository, only when it is set to track the branch with the same name over there):

 git config --global push.default simple

Summary of the comments: the root cause seems to be related to the 1.7.x version of git used for those operation. It seems to work fine with a latest git1.8.3.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • ok.. ran git reset --hard origin/master and then did a pull.. and it attempted a merge( which failed).I fixed this manually... now i get the message (origin/master is 42 commits behind) ( after a fresh clone and pull).. it seems to me that origin/master is not being updated? or the head isn't pointing to it, but to somewhere else..? – user2283043 Jul 05 '13 at 10:43
  • @user2283043 yes, I wonder where your local master is pointing to: what is the output of `git config --get-all branch.master`? – VonC Jul 05 '13 at 10:48
  • Thanks though - you've helped me get a better understanding of it... although i'm still not there yet.. it seems that when i do a 'git pull' I get different information than 'git clone', because the results of 'git reset --hard origin/master' are different for each one.. – user2283043 Jul 05 '13 at 11:12
  • @user2283043 could you at least set first the upstream branch of master as intructed in the answer? `git branch -u origin/master master`? *Then* do a `git reset --hard origin/master` and a `git pull`? – VonC Jul 05 '13 at 11:18
  • I can't run `branch -u` (using 1.7x) so i ran `git branch --set-upstream master origin/master` then `git pull` and this message is returned ` + 05407b6...e6cd630 HEAD -> origin/HEAD (forced update)` - however - I ran git pull a second time and the output was `e6cd630..05407b6 master -> origin/master`. – user2283043 Jul 05 '13 at 11:33
  • @user2283043 did you do the `git reset --hard origin/master` before the `git pull`? Any chance you could upgrade your git to a 1.8.3+? – VonC Jul 05 '13 at 11:37
  • sorry,Yes. I did those 3 commands in order.. `git branch..` `git reset...` then `git pull`.. I'll update to 1.8.3+ now and try again. thanks. – user2283043 Jul 05 '13 at 11:43
  • ok.. Tried it using Git 1.8.3 and it worked! Seems to be back in sync now.. Thank You! – user2283043 Jul 05 '13 at 13:18
  • @user2283043 Excellent! Must have been some weird error linked to the old version of git. Strange. – VonC Jul 05 '13 at 13:38
1

This usually happens when the origin history has been altered by means of "amend", "reset" or similar git commands, see here for some details

Stefano Falasca
  • 8,837
  • 2
  • 18
  • 24