Favor everything on HEAD in a Git merge conflict

Public, Git

harrylevine

Created: Sep 28, 2017     Updated: Sep 28, 2017


Let's say that you are rebasing your current branch on master, and you run into merge conflicts. For example with a blog.rb file. If you have a situation where you might be inclined to fix it by:

A quicker way to achieve that would be to use either of these commands:

git checkout --ours .

The . replaces all files that are currently not committed, with the ones from head/master

git checkout --ours relative_path_to_file

Replaces just the specified file with the one from head/master

i.e. git checkout --ours app/models/blog.rb

git checkout --theirs relative_path_to_file

On the flip side, you may want to favor your current branch, over the one you are rebasing on (master in this case). This --theirs flag would accomplish that.

Git's documentation on --ours and --theirs

https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging