This article explains using Git hooks and Talisman to prevent accidental commits of sensitive data in your codebase.
In this lesson, we’ll cover how to use Git hooks—scripts that run at specific points in your Git workflow—to catch accidental commits of sensitive data. We’ll also introduce Talisman, an open-source tool by ThoughtWorks that automates secret scanning in your repository.
In 2015, a developer accidentally pushed AWS S3 access keys to GitHub. Within five minutes, automated bots exploited those keys for Bitcoin mining, accruing a $2,400 bill. Git hooks help you stop this from happening by running custom scripts at critical events like commits and pushes.
Talisman installs Git hooks to scan outgoing changes for secrets—passwords, API tokens, private keys, credit-card numbers, and more. It also offers a history-scan feature to uncover any secrets already in your repo.
Applies hooks to all repos you clone or init on your machine.
Single-Project (pre-push)
Limits Talisman to one repo, using a pre-push hook.
We’ll demonstrate the single-project approach with a pre-push hook.
Copy
Ask AI
# Download and make the installer executablecurl https://thoughtworks.github.io/talisman/install.sh > ~/install-talisman.shchmod +x ~/install-talisman.sh# In your project directorycd my-git-project~/install-talisman.sh
If you want to apply Talisman globally, see the global_install_scripts in the Talisman repo.