Skip to content

Instantly share code, notes, and snippets.

@jdmallen
Created February 9, 2018 23:10
Show Gist options
  • Select an option

  • Save jdmallen/d4f1ba1aec6db3a1d4d039b2bbce9dbc to your computer and use it in GitHub Desktop.

Select an option

Save jdmallen/d4f1ba1aec6db3a1d4d039b2bbce9dbc to your computer and use it in GitHub Desktop.
Handy git pre-compile hook to prevent yourself from committing passwords
#!/bin/sh
# Save this file in your {repoRoot}/.git/hooks directory with the filename
# 'pre-commit' (no extension), and replace the passwords with your own. Don't
# worry: this file does not get committed. It exists only where you place it.
# Fair warning, though: you are essentially saving your password in plaintext.
# Ensure that you have other security measures in place to protect your data;
# e.g., drive encryption, station locking, etc.
. git-sh-setup # for die
git diff-index -p -M --cached HEAD -- | grep '^+' |
grep 'password1\|password2\|password3\|password4' && die Blocking commit \
because password detected in patch
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment