Skip to content

Instantly share code, notes, and snippets.

@lhotari
Created April 14, 2014 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lhotari/10643365 to your computer and use it in GitHub Desktop.
Save lhotari/10643365 to your computer and use it in GitHub Desktop.
git pre-push hook script to prevent unintentional force pushs
#!/bin/bash
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
echo "Delete of $remote $remote_ref forbidden. Pass --no-verify to ignore check."
exit 1
else
if [ "$remote_sha" != $z40 ]
then
base=`git merge-base $remote_sha $local_sha`
if [[ "${base}" != "${remote_sha}" ]]; then
echo "Force update of $remote $remote_ref forbidden. Pass --no-verify to ignore check."
exit 1
fi
fi
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment