Skip to content

Instantly share code, notes, and snippets.

@jl
Last active October 1, 2023 03:46
Show Gist options
  • Save jl/9316673 to your computer and use it in GitHub Desktop.
Save jl/9316673 to your computer and use it in GitHub Desktop.
Use MacVim to resolve git merge conflicts

When you install MacVim, you have the option of installing command line integration. This basically puts an mvim shell script somewhere in your path, usually /usr/local/bin/mvim. Git has a list of mergetools that it knows about; gvimdiff is in the list, which expects gvim to be in the path.

First, figure out where your mvim script lives, then add a gvim link.

$ which mvim
/usr/local/bin/mvim
$ cd /usr/local/bin
$ ln -s mvim gvim
$ ls -l gvim
lrwxr-xr-x  1 me  admin  4 Mar  2 19:58 gvim -> mvim

Every looks good, so let's tell git to use gvimdiff as the mergetool.

$ git config --global merge.tool gvimdiff

Now, whenever you have a merge conflict, just use git mergetool

$ git cherry-pick 79b80c79
error: could not apply 79b80c7... Updated Footer: blog post, icons
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

$ git mergetool
Merging:
app2/css/forms.less

Normal merge conflict for 'app2/css/forms.less':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (gvimdiff): 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment