diff --git a/.gitattributes b/.gitattributes
index 06d51d28a95..6f7c6d8ba52 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -18,3 +18,18 @@
 #     file gets renamed again ...
 
 ChangeLog       merge=merge-changelog
+
+# Setup whitespace error detection.
+#
+# (1) Spaces before tabs,
+#
+# (2) Use of spaces where a tab should be used,
+#
+# (3) Trailing whitespace,
+
+*.cxx whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.cc whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.[cChH] whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.exp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.tcl whitespace=space-before-tab,indent-with-non-tab,trailing-space