Turbocharging git on Mac OS X

This weekend I discovered two awesome graphical tools to improve my git experience on Mac OS X:

The most awesome is KDiff3 (search for ‘Apple Mac OSX binary’ on that page for the Mac binary). This is a three-way merge tool with an editing panel below. Seriously where has this been all my life? Amazing.

Download it, and install – make sure it’s in your system PATH. Then simply run git config --global merge.tool kdiff3 to set it as your default merge tool. Now every time you get a conflict, your git mergetool command will actually be rather helpful! Basically you are shown the base revision (that both branches split from) in the middle, one branch either side, and an editor below allowing you to pick which side you want and/or edit the file directly.

The second tool I (re)discovered was SourceTree (Mac App Store DL Link). It is a Mac GUI client for git. I’m pretty comfortable with the command line, but what I love about this tool is it allows me to review my changes before I commit them (either staged or unstaged), discard hunks I don’t want, and of course open the file in question for editing. Very convenient. git diff is nice and all, but I love having that handy ‘discard hunk’ button in SourceTree so I can skip my silly changes. For me this is the most useful feature, though no doubt there are others. Oh and it’s free (it’s a bit confusing, as there is a “trial” period, but after the trial you simply register for free, and are given a license).

Refs:
1. Some useful git config tips
2. Graphical Diff Tools for Mac OS X
3. Setting up mergetool on windows


6 comments on “Turbocharging git on Mac OS X

  1. Oh no. You didn’t know about that? A proper diff (and probably more importantly merge) tool is absolutely essential once you go beyond a single developer (and if you go nuts with branches, even if you are).

    I use Beyond Compare 3 (paid for) when I’m running on Windows and it is one of the primary reasons why it just doesn’t feel right developing on anything else. The lack of graphical merge tools on OS X is quite disappointing. There are quite a few diff tools, but merge is often skipped entirely. If you do find something better at any stage, please let me know.

  2. I’ll be sure to let you know! Have you tried KDiff3? It does the job pretty well I think.

    Been flying solo for so long it hasn’t really been necessary, but had a pretty huge merge task on the weekend so I took the time to find some decent tools :)

  3. For a free cross platform diff/merge tool look at Sourcegear Diffmerge. KDiff3 is great, but it takes a long time to start if X.org isn’t already started.

  4. Took me a minute or two to figure out how to “install” KDiff3 from the OS X binary. It’s just an app bundle, so dragging to Applications isn’t going to make kdiff3 appear in your path.

    So if you do move kdiff3 to your /Applications folder, you’ll want to edit your .profile and add a line to add the kdiff3 binary inside of the app bundle to your PATH.

    Step by step, that’s:
    1.) Open a terminal window.
    2.) Type “pico .profile” (yes, I use vim, but there’s no better, instructions-on-the-screen terminal text editor if you don’t)
    3.) Go to the bottom of the file and add this line:

    PATH=$PATH:/Applications/kdiff3.app/Contents/MacOS

    4.) Save.
    5.) Quit pico (vim, emacs, whatever).
    6.) Profit.

    Well, profit except that when I try to launch from SourceTree by right-clicking my conflicted file and choosing “Resolve Conflicts >>> Launch External Merge Tool”, I just get a window flashing briefly and then nothing.

  5. An alternative to adding each application to your PATH is to add a symlink to applications in a folder that’s already on your path. For me, that’s:

    ln -s /Applications/kdiff3.app/Contents/MacOS/kdiff3 /usr/local/bin/kdiff3

Leave a Reply

Your email address will not be published. Required fields are marked *