Skip to content

Instantly share code, notes, and snippets.

@jamwaffles
Last active June 23, 2022 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamwaffles/b3ab1aaf27e4d94b998d to your computer and use it in GitHub Desktop.
Save jamwaffles/b3ab1aaf27e4d94b998d to your computer and use it in GitHub Desktop.
Graphical merge tool for resolving Git merge conflicts

Diff screenshot

Installation

  1. Download DiffMerge from here. It's not the prettiest merge tool but it works.

  2. Install it as usual

  3. Open up a console and run the following commands:

     git config --global merge.tool diffmerge
     git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
     git config --global mergetool.diffmerge.trustExitCode true
    
  4. Check out the branch you want to merge stuff into

  5. Run git merge [other branch]

  6. If you get conflicts, run git mergetool

Usage

A quick note on terminlogy: a local branch is the currently checked out branch. A remote branch is the branch that will be merged into the local branch. For example, if I'm trying to merge awesomeshit into master, I do git checkout master and git merge awesomeshit. master in this case is the local branch, and awesomeshit is the **remote.

Doing a git pull and encountering merge conflicts, the remote source is the stuff coming down from the server (makes much more sense in this context)

The interface will open up 3 panes.

  • The middle pane is the result of the merge.
  • The left pane is the local file (the currently checked out branch)
  • The right pane is the remote file (the file in the other branch you're trying to merge)

Find the next conflict by pressing this button:

Next conflict

If you want to keep your local changes, click this button:

Merge local changes

To take the change from the remote (branch you're trying to merge), click this button:

Use remote change

The centre pane will show the result of the merge. When you're done, click the big ass save button and close the window. The next file in conflict state will then be opened in a new window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment