Skip to content

Instantly share code, notes, and snippets.

@maruf89
Created April 7, 2014 17:52
Show Gist options
  • Save maruf89/10025286 to your computer and use it in GitHub Desktop.
Save maruf89/10025286 to your computer and use it in GitHub Desktop.
Git pre-push hook that will throw an error if you try pushing any code with `DONT PUSH ME` in it
#!/bin/bash
# File lives in .git/hooks/pre-push
# If the following text is found anywhere in the source for HEAD, we will prevent pushing
dont_push_flag="DONT PUSH ME"
flag_found=`git grep --color "$dont_push_flag" HEAD`
if [ -n "$flag_found" ]
then
# Display which commit the first occurence of the flag was found and exit failure
commit=`git log --pretty=format:'%Cred%h%Creset' -S "$dont_push_flag" | tail -n1`
echo "Found $flag_found, first occurence was in $commit, not pushing"
exit 1
fi
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment