Git Cheat Sheet · Integrate

Resolve a conflict

git add <file> (after editing)

A conflict happens when two branches change the same lines: Git does not know which to keep and stops. It marks each area in the file. You choose the right content, delete the markers, stage the file with git add, then finish the merge or the rebase.

What it does

When two branches change the same lines, git stops and asks you which version to keep.

A use case

During a merge, a colleague and you changed the same function.

On the command line

<<<<<<< HEAD … ======= … >>>>>>> <branch>
Your version at the top, the incoming version at the bottom.
git status
Lists the files in conflict ("both modified").
git checkout --ours <file> / --theirs <file>
Keeps one of the two versions entirely.
git add <file>
Marks the conflict as resolved.
git commit · git rebase --continue
Finishes the merge, or resumes the rebase.

In Merathon

  1. The files involved appear in the "Conflicts" section of the right panel.
  2. Click a file: each hunk shows "Current (HEAD)" and "Incoming" side by side.
  3. Click the version to keep, or "Keep both", then "Resolve and stage".
  4. Once all conflicts are resolved, commit (merge) or click "Continue" (rebase).

Frequently asked questions

During a rebase, which version is "ours"?

It is the opposite of a merge: "ours" is the branch you are rebasing onto, "theirs" is your commit being replayed.

How do I avoid conflicts?

Update your branch often, keep pull requests short, and avoid reformatting whole files in the same commit as a substantive change.

See also