Better git conflict resolution between binaries with --theirs and --ours

Posted by on February 24, 2009

Whichever framework I use (Catalyst, Django, etc.) for personal projects, I always develop with a local SQLite database. From time to time they can get out of sync between branches. While working on a project recently, I ran into a Git conflict between a SQLite database on master and an older copy on a development branch.

After checking out the development branch, I ran the merge:

 $ git checkout dev_branch
 $ git merge master

Git notified me that I had a conflicting SQLite file.

I posed the question on the Git irc channel and was told (thanks doener) to use the --theirs flag for git checkout.

 $ git checkout --theirs filename(s)

This says that the file(s) being merged in take precedence over the file(s) in place in the branch, thus running this will overwrite the file(s) on the branch. --ours is the opposite in that the file(s) on the branch take precedence in this merge. More information can be found in the git-checkout docs.

I was then able to complete the merge:

 $ git add umerged_file(s)
 $ git commit

I’m not sure which version of Git this was made available in, but having just upgraded for this feature it is available in the latest stable version (currently

In the old version I was running ( "git reset -- file; git checkout MERGE_HEAD -- file" would have done the same.