There's more...

Having a hook to prevent you from pushing commits that you don't want to push is very handy. You can specify any keywords you want. Words such as reword, temp, nopush, temporary, or hack can all be things you want to stop, but sometimes you want to get them through anyway.

What you can do is have a small checker that checks for specific words, then lists the commits, and asks if you want to push anyway.

If you change the script to the following snippet, the hook will try to find commits with the keyword nopush and list them. If you wish to push them in any case, you can answer the question and Git will push anyway:

#!/bin/bash
COMMITS=$(git log --grep "nopush" --format=format:%H)
if [ "$COMMITS" ]; then
  exitmaybe=1
fi
if [ ...

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.