Ubuntu - Configure Git to Use Meld for Diffs

By default, git will show you diffs in the CLI in a single view, rather than split view. I'm not elite enough to be able to work this way. This tutorial will show you how to configure git to make use of meld to have a split-pane view of your changes.


Install Meld

Install meld if you haven't already got it. Ubuntu/Debian users can simply run:

sudo apt-get install meld -y  

Dixon Dick from the comments pointed out that Mac users can use homebrew to install meld from a tap:

brew install homebrew/gui/meld  

Configure Git

After having installed meld, run the following command to configure git to make use of meld.

curl -s https://scripts.programster.org/scripts/9?output=raw | bash
Alternatively, copy,paste, and execute the following bash script to do the same thing.
# Write a script to run meld for git diffs.How to: Meld for Git diffs in Ubuntu Hardy
cat << EOF > /tmp/git-meld-diff

import sys
import os

os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))

sudo mv /tmp/git-meld-diff /usr/bin/git-meld-diff

# Set the script to be executeable
sudo chmod +x /usr/bin/git-meld-diff

# configure git to use the new script when we run git diff.
git config --global diff.external git-meld-diff

Now when you want to view changes you have made to any files you can run:

git diff  

or if you just want to view changes in one file:

git diff [filename]  




Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.