Trailing whitespaces are always boring. So when we use git, we can set a pre-commit hook to check this for us.
Put following shell to your .git/hook
folder.
#!/bin/sh
red="\033[1;31m"
color_end="\033[0m"
# Check unwanted trailing whitespace or space/tab indents;
if [[ `git diff --cached --check` ]]; then
echo -e ${red}Commit failed${color_end}
git diff --cached --check
exit 1
fi
Don’t forget give execute permission to it.
$ chmod +x pre-commit