Git "Your branch and" source / master "diverge" after a new clone of a remote repo

When I clone a remote repository using

  • git clone 'repo_url'
  • git pull
  • 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 don't have this problem.

Can't sync data to a remote repo? with the boss and the master? How to fix it?

EDIT 1:

when I run the git -a branch: this is how it looks ...

$ 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 does not indicate the last code ... I ran 'git clone', then git reset --hard origin/master and then "git pull", and he tried to merge, which caused conflicts. ..

I think ... the HEAD of the remote repo points to the last commit, origin / master points to another, older commit ... I can check this when I run git show ...

+4
source share
2 answers

Not sure if:

  • there is git push --force on origin someone else made between you cloning a repo and you will pull that repo
  • fetch refspec ( git config --get remote.origin.fetch ) not +refs/heads/*:refs/remotes/origin/* .

But you can reset master quite easily:

 git reset --hard origin/master 

Make sure master tracking origin/master :

 git branch -u origin/master master 

And make sure your push policy is ' simple ' (to list the current branch with the same name in the remote repository only when it is set to track the branch with the same name):

  git config --global push.default simple 

Summary of Comments: The main reason seems to be related to the 1.7.x git version used for this operation. It seems to work fine with the latest git1.8.3.

+7
source

This usually happens when the origin history has been changed using the Change, reset, or similar git commands, see here for some details.

+1
source

Source: https://habr.com/ru/post/1489766/


All Articles