何番煎じだよって感じだけど、適当にググって出てきた奴はメッセージの出し方が個人的に気に入らなかったので自分で作った。
これを .git/hooks/pre-push において実行可能権限を付けると動く。
#!/bin/sh
set -Ceu
remote="${1}"
remote_url="${2}"
while IFS=' ' read -r local_ref local_sha remote_ref remote_sha
do
if [ "${remote_ref}" != "refs/heads/master" ]
then
continue
fi
printf 'Pushing to remote "%s".\n' "${remote}" >&2
printf 'Are you sure to push local "%s" to remote "master"? ' \
"${local_ref#refs/heads/}" >&2
head -n 1 /dev/tty | grep -iq '^y' || exit # return non-zero exit status
done