git - ours & theirs

cleaner merges for everyone

by Nitay Megides
please report issues on github

git merge

let's merge conflicting branch feature into master

$ git checkout master
$ git merge feature

Auto-merging Document
CONFLICT (content): Merge conflict in codefile.js
Automatic merge failed; fix conflicts and then commit the result.

either fix the conflict manually by editing codefile.js, or use

$ git checkout --ours codefile.js

to select the changes done in master

$ git checkout --theirs codefile.js

to select the changes done in feature

then, continue as you would normally merge

$ git add codefile.js
$ git merge --continue

[master 5d01884] Merge branch 'feature'

git rebase

let's rebase conflicting branch feature over master

$ git checkout feature
$ git rebase master

First, rewinding head to replay your work on top of it...
Applying: a commit done in branch feature
error: Failed to merge in the changes.
...

either fix the conflict manually by editing codefile.js, or use

$ git checkout --ours codefile.js

to select the changes done in master

$ git checkout --theirs codefile.js

to select the changes done in feature

then, continue as you would normally do

$ git add codefile.js
$ git rebase --continue

Applying: a commit done in branch feature