A coworker turned me onto this lovely technique the other day. You can use a git pre-push hook to run all of your Golang unit tests before pushing.

To do this, make a the following file: $YOUR_REPO/.git/hooks/pre-push The file must be executable.

The file’s contents should be:


if ! go test ./... ; then
    echo "Rejecting commit. Unit tests failed."
    exit 1

Easy peasy.