Detect git Conflict Markers

Detect git Conflict Markers

If you’re using git, you’ve probably run into a problem at some point where you’ve had to perform a merge, and a merge conflict resulted. This happens when two different commits changed the same line in a file, and git can’t tell which commit should be kept (or if perhaps both should be). In this case, git will reward you with a message like this one:

At this point you need to resolve the conflict, typically by editing the file(s) with a text editor or a diff tool and deciding which commit should “win”. To help you with this, git adds some markers to the file that show the two conflicting choices and which branch they’re coming from:

In this case, you would decide if the 3rd line of the file should be ‘Baz.’ or ‘Bar.’. Then you would delete the one you don’t want, along with all the three line markers (‘<<<‘, ‘===’, and ‘>>>’).

Sometimes, though, you may think you found all of the conflicts, but actually you missed some. So you end up accidentally committing files that still have these marker lines in them. This is bad and will cause you headaches later. If only there were a way to detect this before committing!

Fortunately, git offers such a tool:

If I run this on the file shown above, the result is:


Hopefully this will help you find these markers when you’re not sure you’ve gotten them all, before committing (or after, when you’re trying to clean up a mess). Follow @ohshitgit for more great tips like this one.


  • Danny Feliz

    Hey thank you Steve, very helpful tip