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

  • Another Big TimelineJS Update That You Shouldn’t Even NoticeBut we wanted to warn you ahead of time

    There’s another big but invisible change coming to TimelineJS. In July, we announced a big update to TimelineJS on the day of the release. With some minor exceptions, we were right that most people didn’t notice. Next week, we’ll be making another big update, which, again, we hope you won’t notice. This time, we thought we should announce it ahead of time, because timelines created before January, 2015 will probably stop working unless steps are taken. Timelines...

    Continue Reading

  • Evaluating VR and AR Tools for the ClassroomHow we choose tools for Knight Lab Studio

    In the Knight Lab: Studio class, every Virtual and Augmented Reality project is a blank slate. All of our developers are learning how to make VR and AR for the first time; many of them don’t even consider themselves developers yet. With the exception of a few projects which have run in successive quarters, we’re never building on something that already exists. We go from “New Project” to our final destination in ten weeks. The fact that...

    Continue Reading

  • A Big TimelineJS Update That You Shouldn’t Even Notice

    Today we’re releasing a new version of TimelineJS, but most of you shouldn’t even notice a difference. We make updates to TimelineJS periodically, and we usually don’t say much about it, partly because people who publish timelines using our embed tool are automatically updated to the new version—there’s nothing they need to change. That includes this new release. However, in this case, we thought it was worthwhile posting for two related reasons. First, this release...

    Continue Reading

  • AR Face Filters: How Do They Work and How Are They Changing Us?

    This video explains the mechanisms behind how selfie filters change our digital images and then how this might psychologically affect us. To make this video, I researched “Snapchat Dysmorphia” and also looked for the technical understanding of selfie filters. Before creating this video, I made a selfie filter for the Knight Lab using Spark AR to get a sense of how face deformation would work in Instagram selfie filters. The animation workflow for me looked...

    Continue Reading

  • 9 Important VR Experiences for Journalists to See

    In an era where social media outpaces print newspapers in the U.S. by a whopping 4% (Pew Research Center, 2018), there is much to be said about the role of interactive media technology in minimizing this gap between technology and storytelling. How can publications, and the journalists within them, use interactive media technology to re-engage with this lost audience? And why might this shift towards digital storytelling, such as VR, be more valuable for journalism than...

    Continue Reading

  • 7 Reflections on SRCCON:Productthe first conference for “product thinkers” in media

    On Feb. 8 in Philadelphia, I was lucky to be one of about 150 participants at SRCCON:Product, the first conference for “product thinkers” in media. A few reflections on what I saw and learned: 1. A quarter of a century into the digital age, we are finally figuring out how to build media products In 1995, I was named the first online director for The Miami Herald, with responsibility for launching the “Internet edition” of...

    Continue Reading

Storytelling Tools

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

View More