#!/usr/bin/env bash
read old_sha new_sha refname
# if we delete branch don't do anything
if [[ "$new_sha" =~ ^0+$ ]]; then
exit 0
fi
# if we push new branch we need to set correct old_sha
if [[ "$old_sha" =~ ^0+$ ]]; then
old_sha=`git rev-list $new_sha --not --branches | tail -n 1`
fi
# check if code includes conflict markers
if git diff "$old_sha" "$new_sha" | grep -qE '^+?(<<<<<|>>>>>)'; then
echo "Saw a conflict marker in $(basename "$refname")."
exit 1
fi
Script based on: http://stackoverflow.com/questions/11358225/how-to-prevent-push-if-there-are-unresolved-conflicts-using-hook-in-git