Skip to content

Instantly share code, notes, and snippets.

Last active March 20, 2017 09:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Block to commit if user's email not match
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# To enable this hook, rename this file to "pre-commit".
accept_email() {
CURRENT_USER_EMAIL=$(git config --list | grep | awk -F"=" '{print $2}')
if [ "${CURRENT_USER_EMAIL}" != "${substring}" ]; then
printf "Not match" > /dev/null
WHITE_LIST="${WHITE_LIST}\n> ${substring}"
exit 0
# Change for your accepted email addresses
accept_email ""
accept_email ""
printf "Your current git <%s> NOT MATCH any approved emails\n" "${CURRENT_USER_EMAIL}"
printf "%b\n\n" "${WHITE_LIST}"
printf "Check ~/.gitconfig for more\n"
exit 1
Copy link

egel commented Mar 20, 2017

Usage download and save into .git/hooks/pre-commit:

Change example email addresses for your own.

cd <your project git root directory>
wget -P ".git/hooks"
chmod +x .git/hooks/pre-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment