Skip to content

Instantly share code, notes, and snippets.

@ktec
Last active May 17, 2016 12:06
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 ktec/62099005a6f94c6e2924c328bb7103cb to your computer and use it in GitHub Desktop.
Save ktec/62099005a6f94c6e2924c328bb7103cb to your computer and use it in GitHub Desktop.
Whenever you push to remote that has "production" in its name,
this hook will show commits and changes and then ask for confirmation.
Copy or symlink to:
.git/hooks/pre-push.
Make the file executable:
chmod +x .git/hooks/pre-push
#!/bin/bash
if [[ "$1" =~ "production" ]]; then
read -a array
pushed_ref=${array[1]}
remote_ref=${array[3]}
echo "You are pushing to PRODUCTION! Here are the changes you're about to push:"
echo
echo "# Commits:"
git log --oneline -5 $remote_ref...$pushed_ref
echo
echo "# Files changed:"
git diff --name-only $remote_ref $pushed_ref
echo
echo
read -p "Are you sure? [Y] " -r < /dev/tty
echo
if [[ $REPLY = 'Y' ]]; then
exit 0
else
exit 1
fi
else
exit 0 # push will execute
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment