Video in progress

Strong Junior 🌿 Git

You accidentally committed the database password and pushed to GitHub. What do you do first?

First you change the password (rotate it): assume it is already exposed. Then you take it out of the code and move it to the environment or a secret manager, and if needed, clean it out of the history too.

📖 Answer

Most people rush to clean the history first. But the moment you push, bots may have already scanned the secret, and it also remains in forks and CI logs. So the order is:

  1. Rotate. In the database, in AWS, wherever it is: a new password/key, and delete the old one.
  2. Remove it from the code: ${DB_PASSWORD} in application.yml, and the value in the environment or Vault.
  3. Clean the history (if policy requires it): with git filter-repo or BFG, then force push and tell the team, since everyone has to clone again.
spring:
  datasource:
    password: ${DB_PASSWORD}

To prevent it: .env and *-local.yml in .gitignore, a scanner such as gitleaks in a pre-commit hook, and secret scanning turned on in GitHub. A plain git revert does not help here, because the password stays in the old commit.