The question
I have a local repo with 3 commits:
A -> B -> C
And the remote repo has another 3 commits:
A -> B -> D
How to make git pull to resolve the divergent by discarding all local commits? The local repo after git pull --some-magic should be:
A -> B -> D
Note that, git reset HEAD~1 --hard won't work, because my script doesn't know how many commits must be reverted to avoid a conflict.
Why I need this
I'm writing a script to sync between github and gitlab repositories. One of them is a read-only mirror. My scripts just try git pull --force from origin1 and git push to origin2.
However, if someone changed the history of origin1, the git pull in my script would fail with an error message. The only way to solve the problem is delete the whole local repository, and perform git clone from stretch. It's wasting bandwidth and slow!