#!/usr/bin/env bash block_push=0 while read -r old new refname; do while read -r added deleted filename; do if [[ "$added" == "-" && "$deleted" == "-" ]]; then block_push=1 echo "ERROR: ${filename} is a binary file." fi done < <(git diff --numstat "${old}..${new}") if [[ $block_push -eq 1 ]]; then echo "The ref '${refname}' has been rejected" fi done if [[ $block_push -eq 1 ]]; then echo "Binary files blocked. Please use git-lfs to push to this repo." exit 1 fi