Auto Resolve Git Rebase, Take Incoming Change


It's a nightmare that clears up quickly. You rebase, and it produces a merge conflict. Instead of looking at the file contents, you decide to simply take the incoming changes.

The Scenario

You're on your feature branch:

git checkout myfeature

You try to merge the main branch:

git rebase main

This produces conflicts. Who has time to edit conflict markers?

Accept Changes from main

In this scenario, you know main is pristine. If there is a conflict, you'd like to just accept main's authoritative version of things.

First, identify the path from git root to the file that is in conflict. Use the git checkout --ours command:

git checkout --ours path/to/fileInConflict.js
git add path/to/fileInConflict.js

You've now automatically resolve the conflict markers. Continue with:

git rebase --continue

Yours, Mine and Ours

To me, the option for this command is backward. This is the option legend matched with the branches in this scenario:

  • --ours is main branch
  • --theirs is myfeature branch

What other methods do you use to easily resolve your git conflicts?