Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

Solving Conflicts with meld

I am on a branch that was created from the main branch.

Now I want to merge the new main branch into my branch again.

But someone else changed parts which I also changed on my branch.

There is a conflict.

❯ git fetch
❯ git merge origin/main

Auto-merging internal/foo/api/v1beta1/mycrd_types.go
CONFLICT (content): Merge conflict in internal/foo/api/v1beta1/mycrd_types.go

I use meld for solving conflicts.

If you want to launch plain meld for one merge, use:

git mergetool --tool=meld

Now a nice UI opens, and you will see three columns:

  • On the left side, you see your original code (before starting the merge).
  • In the middle, you see the result of the automatic merges done by Git.
  • On the right side, you see "theirs" (new main branch).

The green and blue parts are automatically resolved. You do not modify these in most cases.

You will see conflicts marked with a red background. In the middle column of a conflict line, you see (??).

You can take the left (your side), the right side (theirs), or modify the code manually.

Finally, go to the middle column and press Ctrl+S to save your changes. Then close the UI. The UI will reopen if there is a second file with a conflict.