A pre-push hook script will verify what is about to be pushed. This shell script will ensure that you don’t leave any local edits or untracked files unattended. If this script exits with a non-zero status nothing will be pushed.
#!/bin/bash
# No Local Uncommitted Edits
# ==========================
current_diff=$(git diff --shortstat)
if [ -n "$current_diff" ]
then
echo "You're about to push, found local edits:"
echo "${current_diff}"
read -p "... is that what you intended? [y|n] " -n 1 -r < /dev/tty
echo
if ! echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 1 # push will not execute
fi
fi
unset current_diff
# No Local Uncommitted Files
# ==========================
current_untracked=$(git ls-files --others --exclude-standard)
if [ -n "$current_untracked" ]
then
echo "You're about to push, found untracked files:"
echo "${current_untracked}" | sed 's/^/ /'
read -p "... is that what you intended? [y|n] " -n 1 -r < /dev/tty
echo
if ! echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 1 # push will not execute
fi
fi
unset current_untracked
exit 0