Last Updated: October 12, 2018
· suneelius

For cleaner merges, use a strategy

Suppose you're merging in branch A and you have a TON of conflicts.

Not only is it going to take you forever, but the worst part is that for this particular merge, in every conflict, you're just going to reject branch A's version and side with the current branch.

Luckily, there's a way to avoid this headache-inducing tedium!

If you're merging in a branch and for all the conflicts, you're going to side with the same one branch, just specify a strategy (which branch to side with).

In our case, we side with our current branch:

git merge A -X ours

In the reverse case, we side with A's version in every conflict:

git merge A -X theirs

4 Responses
Add your response

Nice, this maybe useful when merging a forked repo with the original repo (since we know the original maintainer have new update to their original repo).

over 1 year ago ·

@drabiter But in any case you will either loose your or other repo's work. So this should be used with care i.e. before merging other work should be checked and then decide whether we use "ours" or "theirs"

Of course we don't have head ache of resolving conflicts

over 1 year ago ·

Thanks for the tip, will definitely keep this in mind! :D

over 1 year ago ·

@copyninja Yeah reading the conflict is still a requirement but at least we have lazy option :)

I wonder if we can double-siding. Say there are conflict on 2 files and we want to side with theirs for file A and ours for file B.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post a tip
Filed Under