That's the solution that I adhere to. But on a team with several devs, how do you prevent that from happening? Or how do you prevent yourself from accidentally(!) doing so (i.e. during the late-night coding sessions)?
review review review review review always review your code before a commit to master
one way to prevent the accident during a downtime panic at 2am is to NEVER be in the habit of doing it anyway.
If you never put credentials in your code, then even during panic mode you won't do it.