A shell script to check and format only the staged .go files before committing. If any staged Go files are not properly formatted, it automatically formats them using gofmt, lists the affected files, and prevents the commit so you can stage the changes and try again.
Save this script as .git/hooks/pre-commit and give it execute permission.