This is a quick pre-commit git hook to prevent committing annonymously as root – it refuses to allow root to commit directly and insists that –author is given if a user is commmitting via sudo.
# Check that if committing as root the author is set, as far as possible.
if [ "$UID" -eq 0 ]
echo "Warning: Committing as root." >&2
if [ -n "$SUDO_USER" ]
if ! echo $SUDO_COMMAND | grep -q -e '--author'
cat - >&2 <
or (if you have committed before - see 'man git-commit'):
git commit --author=some_pattern_that_matches_your_name
Previous authors in repository:
$( git log --all --format='%an <%ae>' | sort -u )
echo "Committing as root, without using sudo. Please do not do this." >&2
if [ "$abort" -ne 0 ]
echo -e "\n\ncommit aborted\n" >&2