If you like me, notoriously forget to check that commmiting changes still allows your project to compile, use the following trick.

Go to your project’s git directory. Enter to the hooks dir.

cd ~/projects/myawesomeproject/.git/hooks

Create file named pre-commit

touch pre-commit

Copy-paste following content to that file.

make clean ; make

Pre-commit is a hook launched, as the name suggests, before commiting. For all non-zero returned statuses, commit will be stopped.

There should be one more explanation from me. I assume, that you are using some makefile dependent project. In that case you have to enter commands appropriate for your configuration.

There are some samples in this directory. You can check them for other possible uses of git hooks.