Skip to content

Instantly share code, notes, and snippets.

@fukawi2
Created August 1, 2019 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fukawi2/8296c0efa30102ca5595083471d79a22 to your computer and use it in GitHub Desktop.
Save fukawi2/8296c0efa30102ca5595083471d79a22 to your computer and use it in GitHub Desktop.
Avoid committing to git as root
#!/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