Skip to content

Instantly share code, notes, and snippets.

@limpido
Created June 23, 2025 09:02
Show Gist options
  • Save limpido/2fb7c7b713faf2e70678091836a0a925 to your computer and use it in GitHub Desktop.
Save limpido/2fb7c7b713faf2e70678091836a0a925 to your computer and use it in GitHub Desktop.
git pre-commit hook to check whitespace errors
1 #!/usr/bin/bash
2
3 if git rev-parse --verify HEAD >/dev/null 2>&1
4 then
5 against=HEAD
6 else
7 echo "pre-commit: About to create the first commit..."
8 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 # magic commit ID for empty commit
9 fi
10
11 if ! git diff-index --check --cached $against
12 then
13 echo "pre-commit: Aborting commit due to whitespace errors"
14 exit 1
15 fi
16
17 exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment