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:

#!/bin/sh

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

Easy peasy.