How the git mergetool solved my anxiety, fears, and most importantly, my merge conflicts

Back in March, another student fellow Nicole Zhu and I worked on a team challenge for which we were the primary coders. One day, she emailed me:

“Uhh. I messed up. Sorry. I think you have to delete your repo.”

She had been attempting to resolve a merge conflict, ended up in vim somehow, nope’d out of there, and messaged me to let me know her solution was to delete everything and re-clone.

More sadly, I completely empathized with her active avoidance of figuring out how to actually resolve the merge conflict because I didn’t know what was happening either.

We know how this story ends. We tried to avoid merge conflicts like bad news, but when Nicole and I started working on Romaine together as its primary coders, we decided we could no longer suffer its intimidation like battered warriors of a mythical enemy.

But I say a mythical enemy, because as it turns out, resolving merge conflicts isn’t as scary as all those tutorials out there make it seem. Yes, you’ll have to witness some alarming red lines flash across your screen on your command line. Yes, it will feel painful, accepting your ill fate, but only for a little bit.

Because there’s this thing called the git mergetool, and it’s kind of like the magic wand everybody forgot to tell you existed (everybody, except Joe Germuska).

Let me explain.

1

Uh oh. This is an impending merge conflict. We know this because:

error: failed to push some refs to ‘git@github.com:suyeonson/merge_conflict.git’

This indicates there are some changes on my remote branch that would conflict with the changes I’m trying to push from my local files.

All right, fine. Let’s pull those changes first.

2

There’s that merge conflict.

CONFLICT (content): Merge conflict in index.html

Now, instead of digging through your files to find those pesky >>> and === signs that indicate where you should be looking, type:

git mergetool

This might lead you to this message:

3

Lucky for me, opendiff is my default merge resolution tool here even though I have not configured my mergetool. But if you’re like Nicole, where your computer decides that of all things, vimdiff (a resolution tool using the godforsaken vim -- you know, the thing you can never figure out how to navigate), type:

git config --global merge.tool opendiff

git mergetool -y

This configures your global git settings to make your default merge tool opendiff, then gives your computer the go ahead to use it.

What this launches is a GUI that looks something like this:

4

Each little bubble indicates where there is a difference between the two files, where the left pane is your local file and the right pane is the remote file with someone else’s changes. Using your arrow keys, you can indicate which pane’s difference/change you would like to keep.

See that dot in the lower middle of the pane? Drag it up, for your sanity:

5

And now you’ve got a third pane, which is the final version of your file, given the changes you’ve decided to keep or toss (here, I’ve decided to go with all of the remote file’s changes. Yes, I know that’s broken code.)

When you’ve looked over that third pane, simply save (command + s) as you would a document.

Boom. You’re done.

“Merge conflicts threw a wrench in my understanding of GitHub,” Zhu said. “Collaboration is a key component of GitHub and it was annoying that I didn’t know how to take advantage of that collaborative aspect. In the real world, you can’t just delete a repo and start over.”

Lucky for us, we got through this ordeal together. The curse of unknowledge and fear has been lifted.

About the author

Suyeon Son

Undergraduate Fellow

Latest Posts

  • Introducing StorylineJS

    Today we're excited to release a new tool for storytellers.

    StorylineJS makes it easy to tell the story behind a dataset, without the need for programming or data visualization expertise. Just upload your data to Google Sheets, add two columns, and fill in the story on the rows you want to highlight. Set a few configuration options and you have an annotated chart, ready to embed on your website. (And did we mention, it looks great on phones?) As with all of our tools, simplicity...

    Continue Reading

  • Join us in October: NU hosts the Computation + Journalism 2017 symposium

    An exciting lineup of researchers, technologists and journalists will convene in October for Computation + Journalism Symposium 2017 at Northwestern University. Register now and book your hotel rooms for the event, which will take place on Friday, Oct. 13, and Saturday, Oct. 14 in Evanston, IL. Hotel room blocks near campus are filling up fast! Speakers will include: Ashwin Ram, who heads research and development for Amazon’s Alexa artificial intelligence (AI) agent, which powers the...

    Continue Reading

  • Bringing Historical Data to Census Reporter

    A Visualization and Research Review

    An Introduction Since Census Reporter’s launch in 2014, one of our most requested features has been the option to see historic census data. Journalists of all backgrounds have asked for a simplified way to get the long-term values they need from Census Reporter, whether it’s through our data section or directly from individual profile pages. Over the past few months I’ve been working to make that a reality. With invaluable feedback from many of you,......

    Continue Reading

  • How We Brought A Chatbot To Life

    Best Practice Guide

    A chatbot creates a unique user experience with many benefits. It gives the audience an opportunity to ask questions and get to know more about your organization. It allows you to collect valuable information from the audience. It can increase interaction time on your site. Bot prototype In the spring of 2017, our Knight Lab team examined the conversational user interface of Public Good Software’s chatbot, which is a chat-widget embedded within media partner sites.......

    Continue Reading

  • Stitching 360° Video

    For the time-being, footage filmed on most 360° cameras cannot be directly edited and uploaded for viewing immediately after capture. Different cameras have different methods of outputting footage, but usually each camera lens corresponds to a separate video file. These video files must be combined using “video stitching” software on a computer or phone before the video becomes one connected, viewable video. Garmin and other companies have recently demonstrated interest in creating cameras that stitch......

    Continue Reading

  • Publishing your 360° content

    Publishing can be confusing for aspiring 360° video storytellers. The lack of public information on platform viewership makes it nearly impossible to know where you can best reach your intended viewers, or even how much time and effort to devote to the creation of VR content. Numbers are hard to come by, but were more available in the beginning of 2016. At the time, most viewers encountered 360° video on Facebook. In February 2016, Facebook......

    Continue Reading

Storytelling Tools

We build easy-to-use tools that can help you tell better stories.

View More