Unconditionally Accepting All Merging-In Changes During a Git Merge

Merge conflicts suck. It is not uncommon, however, that you often just know that you really just want to accept all the changes from the branch that you are merging in. Which makes things a lot simpler conceptually. The Git documentation suggests that this can also be procedurally simple as well, as it mentions the “-s theirs” merge strategy which does just that, i.e., unconditionally accept everything from the branch that you are merging in:

$ git merge -s theirs

Unfortunately, however, running the above command results in an error message along the line of “theirs” is not a known strategy. This is because, as discussed here (original reference here), this option has been removed from Git. I am sure the reasons for this are sound. But it is too bad that the documentation (as of my current installation, 1.7.7) has not been updated to reflect these changes. Really too bad. Really, really, really, really too bad. Because it takes a potentially dangerous, always stressful, and sometimes frustrating experience and makes it all the worse due to outright false documentation. Still, as an open source developer myself, I recognize that the time, energy, and effort demands of maintaining open source software have to be fitted in in between the demands of the other aspects of life, and how there consequently is sometimes considerable lag in updating what usually receives the lowest priority: the documentation. In any case, luckily the page referred to previously provides some nice solutions for achieving the same effect as “-s theirs, which I am summarizing here for my own reference.

Method #1

git merge -s ours ref-to-be-merged
git commit -F .git/COMMIT_EDITMSG --amend

Method #2

git checkout MINE
git merge --no-commit -s ours HERS
git rm -rf .
git checkout HERS -- .
git checkout MINE -- debian # or whatever, as appropriate

Method #3

# get the contents of another branch
git read-tree -u --reset
# selectivly merge subdirectories
# e.g superseed upstream source with that from another branch
git merge -s ours --no-commit other_upstream
git checkout HEAD -- debian/
git checkout HEAD -- .gitignore
git commit -m 'superseed upstream source' -a

Of these, I tried the first method, and it worked like a charm. YMMV.