Avoid pushing in-progress changes

When working on multiple files or sections of code I often leave XXX tags with comments like “remove this line”, “uncomment this call”, “rename me”, etc., to remember to change back or finish something before pushing to remote. While tags are highlighted on most text editors it is still easy to miss them, so I have the following Git pre-push hook to abort a push if the tag is found in the changes:

#!/usr/bin/env bash
# Remember to set your hooks path (e.g. git config --global core.hookspath "~/.git/hooks/")

remote_name="$1"
commit=$(git merge-base --all HEAD $remote_name/HEAD)

git diff --no-color -U0 -SXXX $commit | grep -q "^\+.*XXX"

if [[ $? -eq 0 ]]; then
        git diff -SXXX $commit
        echo -e "\n$0: string \"XXX\" found in diff, aborting push..."
        echo -e "\nYou can disable this check using git push --no-verify"
        exit 1
fi

As you can provably see it’s not perfect but so far I’ve never had to disable it for any push.