Resolving Git Merge Conflicts with Vimdiff
I was facing an issue while pulling changes from my remote repository on my server because I had already made a few changes on my local machine. Git naturally complained and threw me into a merge conflict situation.

If you’ve ever been in this spot, you know how tricky it can be to resolve conflicts—especially if you’re using vimdiff as your Git mergetool. At first glance, vimdiff looks intimidating: multiple split windows, lots of color highlights, and not much explanation. But once you understand the basics, it becomes a really powerful way to resolve merge conflicts.
This post is a short tutorial to walk you through vimdiff for Git merges, explaining what LOCAL, BASE, and REMOTE mean, and how to navigate effectively. I’ll assume you know a little bit of Vim (moving around, saving, quitting, switching between windows). If you don’t, you might want to check out a quick primer first. Some understanding of Git and branching is also required.
What Happens During a Git Merge Conflict?
When you run git pull
(or git merge
), Git tries to automatically combine your local changes with the changes from the remote branch. If both you and someone else edited the same part of a file, Git cannot decide whose version to keep. That’s when you get a merge conflict.
This is where vimdiff comes in.
Launching Vimdiff as Git Mergetool
You can set vimdiff as your default mergetool:
git config --global merge.tool vimdiff
git mergetool
Running git mergetool
will open conflicting files in vimdiff.
Understanding the Windows: LOCAL, BASE, REMOTE, MERGED
When vimdiff opens, you’ll usually see 3 or 4 splits depending on your config. Here’s what they mean:
- LOCAL → Your current branch (your own changes).
- REMOTE → The branch you are merging from (changes from others/remote repo).
- BASE → The common ancestor where both branches started from.
- MERGED → The final version you are editing to resolve the conflict.
Usually, the bottom-right window (MERGED) is the one you’ll be saving after choosing which lines to keep.
Basic Navigation in Vimdiff
- Switch between windows:
Ctrl-w w
- Move left/right/up/down between windows:
Ctrl-w h/j/k/l
- Quit a window:
:q
- Save the merged file:
:wqa
(write all and quit all)
How to Choose Between Versions
The power of vimdiff lies in being able to copy chunks of code from one version to another.
The most common commands are:
:diffget LOCAL
→ take the change from your local branch:diffget REMOTE
→ take the change from the remote branch:diffget BASE
→ take the change from the base version
Or, shorter versions:
:diffget //2
→ LOCAL:diffget //3
→ REMOTE
For example, if you decide the remote version is correct, move to the MERGED window and run:
:diffget REMOTE
The conflicting section will be replaced with the remote change.
Workflow Example
- Run
git pull
→ conflict arises. - Run
git mergetool
→ vimdiff opens. - Inspect the differences between LOCAL and REMOTE.
- In the MERGED window, use
:diffget
to pick lines from LOCAL or REMOTE. - Save and quit (
:wqa
). - Commit the merge resolution:
git commit
Why Vimdiff?
At first it feels heavy, but once you get comfortable:
- You see all versions side by side.
- You can mix and match—take some lines from LOCAL, others from REMOTE.
- You avoid the risk of leaving Git conflict markers (
<<<<<<<
,=======
,>>>>>>>
) in your code.
It’s a clean and efficient way to resolve conflicts once you know the commands.
Final Thoughts
If you’re comfortable with Vim, then learning vimdiff is worth the effort. It saves time, gives clarity in conflicts, and prevents messy mistakes. Next time Git yells at you about conflicts, you’ll know exactly what to do..