Reputation: 143
Is it correct that for git pull (and thus git merge by extension) to throw merge conflicts, the local and remote repositories have to be out of sync ? Basically, is it necessary for these 2 conditions to be met in order to get a merge conflict -
Upvotes: 0
Views: 2850
Reputation: 6726
Yes, both repos must have at least one unsynchronized commit each that changes the same lines. Otherwise, the most up-to-date change in the remote branch will be transferred to the local clone without a conflict.
Upvotes: 0
Reputation: 536027
Pretty much correct.
As for the merge: Certainly there must be a commit on your side that the remote doesn't have; otherwise we'd fast forward, which is not really a merge. And there must be a commit on the remote that you don't have: otherwise nothing would happen (you'd be up to date).
But that is merely the prerequisite to get a merge in the first place.
As for the merge conflict: It doesn't have to be the same line of code, it could be an adjacent line. And there are other ways to get a merge conflict, like one side deletes the file entirely.
What matters, however, is not "one of the commits made locally". It is the totality of what has been done on each side since the last common commit. If you had a commit that edited the same line he edited, and then you had another commit that changed it back again or changed it to what he has, there is no conflict.
Upvotes: 2