Have you ever pushed to a branch that you weren't supposed to push to? Me too. If the remote isn't configured to prevent you from doing that, this appears to be the easiest way to avoid embarrassment:

git config branch.<branch>.pushRemote = no_push

Credits: https://stackoverflow.com/a/57998309/5091738

As I understand it, this merely sets the push remote of your local <branch> to the non-existent remote branch no_push. You can override it by running:

git push origin <branch>

Don't try it on a live master branch. (Yes, I was that stupid.)

By the way, to avoid the embarrassment of committing files with secrets in them, don't put them in the directory with the Git repo in the first place. Keep them outside in the form of environment variables etc. – Credits: https://pragprog.com/titles/mnee2/release-it-second-edition/