Fixing Git Merge Conflicts: Reference and Examples

Last updated:
Table of Contents

Git version used for examples: 2.7.4

All examples use origin and master as the remote and branch names, respectively

Pull code, use "theirs" for all conflicts

$ git pull -s recursive -X theirs origin master

Pull code, use "ours" for all conflicts

$ git pull -s recursive -X ours origin master

Fix conflict in file using "our" changes

$ git checkout --ours my_file_name.txt

Fix conflict in file using "their" changes

$ git checkout --theirs my_file_name.txt

Fix all conflicts using "our" changes

$ git checkout --conflict=merge .
$ git checkout --ours .

Then run git add and git commit on fixed files to signal that conflicts were fixed.

Fix all conflicts using "their" changes

$ git checkout --conflict=merge .
$ git checkout --theirs .

Then run git add and git commit on fixed files to signal that conflicts were fixed.


See also

Dialogue & Discussion