Skip to content

Instantly share code, notes, and snippets.

@maxmarkus
Created March 24, 2016 13:26
Show Gist options
  • Save maxmarkus/8a81edd58dd65a45731f to your computer and use it in GitHub Desktop.
Save maxmarkus/8a81edd58dd65a45731f to your computer and use it in GitHub Desktop.
Git pre-commit hook to prevent checking in non-resolved merge conflicts.
#!/bin/bash
# Check for merge conflicts
# Tested on Linux and Mac
# Simple check for merge conflics
conflicts=`git diff --cached --name-only -G"<<<<<|=====|>>>>>"`
# Something went wrong
if [[ -n "$conflicts" ]]; then
echo
echo "Unresolved merge conflicts in these files:"
for conflict in $conflicts; do
echo $conflict
done;
exit 1;
fi
exit 0
@cawal
Copy link

cawal commented Jul 1, 2020

Awesome! Thank you!

@MuYunyun
Copy link

MuYunyun commented Jul 2, 2020

It seems ok.

@Lubba-64
Copy link

pre-commit has an official hook for this.

Just add this to your pre-commit-config.yaml

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: check-merge-conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment