Git: You are in the middle of a conflicted merge.

So i’m not a git expert. But i’ve been using it for about a month and i’m mostly really happy. The only time it drives me crazy is when i get this damned message.

~/code/tt (master) $ git pull
You are in the middle of a conflicted merge.

It’s like this swamp in the gitverse. Normally merging is fine everything goes along with tons of merges branches for each feature which i merge back in. I really like it. But when merges fail git does not provide any path out of the swamp. Your magical merging technology has failed you and now you must find your own way out. Every command leads to the same damned message. “You are in the middle of a conflicted merge.” Well i know that! Trying git resolve doesn’t do much, that’s not even a command.

~/code/tt (master) $ git resolve
git: 'resolve' is not a git-command. See 'git --help'.

So what to do, well first resolve the conflict in your merging program of choice. Almost always for me it’s just textmate, open the damned conflicted file and edit it. FileMerge and others work too, but we’re just diffing shit, it’s not too hard.

Now here’s the trick, once you fix the problem, add the files which you’ve had to edit, and commit them.

~/code/tt (master) $ git add lib/im/response.rb
~/code/tt (master) $ git commit -m 'I hate failed merges'
Created commit 34d2648: I hate failed merges


That’s it. I’m writing this blog post because i keep forgetting what to do, and when i search on google for the error message, You are in the middle of a conflicted merge. i get some damned message on the kernel dev list about the development of git.

So here the steps are:

  1. Pull the update from master, or whereever – git pull
  2. See the dreaded merge failed message
  3. Edit the files which failed to merge correctly cleaning up the code
  4. Run your tests / specs just to make sure you caught everything
  5. Add and commit the manually merged file. git add path/to/file.rb; git commit -m “work damnit”
  6. Go back to pushing and pulling in peace


Git’s an amazing piece of technology with some really broken parts to it’s interface which makes learning how it works hard.

To me it’s similar to the differences between the GNU stack and Solaris. I came to know about the GNU tools through Linux, it was just how everything worked. Then one day i had to use Solaris, and the commands had all the same names, and worked. But not as well. The GNU tools have really amazing user interface and interaction design. Seriously. Read GNU Standards for Command Line Interfaces and you’ll be amazed, that’s what we all think of as linux and unix. It works, it’s standardized. It makes it easy to guess what’s next and discover how the application works. It’s not given credit, but that document, and the extensive toolset like readline, built on it, is what makes the internet work. It’s discoverable, it’s built on the idea that you can pipe information from one program to another, and that they will all work. If you don’t believe me, just look at DJB’s amazing, but far from standard apps.

So what should git do? Well it should suggest a solution. Or make a solution documented in the examples of the man file. It’s pretty damned simple, fix the merge, add the file, commit, and you’re done. Instead it locks up and prevents you from doing anything until you intuit your way out of the problem. Insanity.

PS. Yes i’m lazy and should submit the fix myself, people are submitting contributions to git all the time.


About this entry