Custom Pre-Commit and Post-Commit Git Hooks for Security and Backups
Briefly

Git hooks are scripts that Git runs before or after certain events like committing, pushing, or merging code. They can be used to enforce rules and automate tasks, making sure code quality, security, and backup processes are maintained consistently across the team.
Pre-commit hooks run before a commit is finalized, allowing us to inspect the code and abort the commit if necessary. On the other hand, post-commit hooks run after a commit, useful for tasks such as logging, backup, or syncing actions that occur after the commit is successful.
While tools like GitLeaks and GitGuardian provide advanced secret-scanning and security monitoring for our repositories, manually writing hooks gives us complete control over our logic and scope. We can tailor the checks and automations precisely to our team's workflows.
We had the goals of not checking in any sensitive information while still keeping files with blank values in GitHub. Specifically, we aimed to prevent environment-specific config files from being included in commits.
Read at Medium
[
|
]