Push protection

Secure your secrets by stopping them from ever reaching your repository with push protection.

What is push protection?

Push protection is a secret scanning feature designed to prevent hardcoded credentials, such as secrets or tokens, from ever being pushed to your repository. Rather than alerting you to credential leaks after the fact, push protection blocks pushes that contain secrets before they reach your repository.

How push protection works

Push protection blocks secrets detected in:

When push protection detects a potential secret during a push attempt, it will block the push and provide a detailed message explaining the reason for the block. You will need to review the code in question, remove any sensitive information, and reattempt the push.

Types of push protection

There are two types of push protection:

Push protection for repositories

You can enable push protection for repositories at the repository, organization, or enterprise level. This form of push protection:

Tip

Regardless of the enablement status of push protection, organizations on GitHub Team and GitHub Enterprise can run a free report to scan their code for leaked secrets. The report also shows how many secret leaks could have been prevented by push protection. See Secret security with GitHub.

Push protection for users

Push protection for users is only available on GitHub.com, and is specific to your GitHub account. This form of push protection:

Push protection bypass and alerts

For push protection for repositories, by default, anyone with write access to the repository can bypass push protection by specifying a bypass reason. When a contributor bypasses a push protection block, GitHub:

This table shows the behavior of alerts for each bypass reason a user can specify.

Bypass reason Alert behavior
It's used in tests GitHub creates a closed alert, resolved as "used in tests"
It's a false positive GitHub creates a closed alert, resolved as "false positive"
I'll fix it later GitHub creates an open alert

If you want greater control over which contributors can bypass push protection and which pushes containing secrets should be allowed, you can configure delegated bypass for push protection. With delegated bypass, you can grant actors:

Benefits of push protection

Customization

After you enable push protection for repositories, you can customize it by: