Created
August 1, 2019 01:57
-
-
Save fukawi2/8296c0efa30102ca5595083471d79a22 to your computer and use it in GitHub Desktop.
Avoid committing to git as root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# avoid accidentally committing to git repos as root. | |
# save to /usr/local/bin/git | |
# | |
set -eu | |
git_cmd="${1:-}" | |
if [[ -n "$git_cmd" ]] ; then | |
if [[ "$git_cmd" == 'commit' ]] ; then | |
if [[ "$(whoami)" == 'root' ]] ; then | |
echo "ERROR: You may not commit as root. Reveal your identity!" | |
exit 1 | |
fi | |
fi | |
fi | |
/usr/bin/git "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment