Skip to main content

为存储库启用推送保护

通过推送保护,secret scanning 会阻止参与者将机密推送到存储库,并在参与者绕过该阻止时生成警报。

谁可以使用此功能?

具有管理员角色的存储库所有者、组织所有者、安全管理员和用户

About enabling push protection

To enable push protection for a repository, you must first enable secret scanning. You can then enable push protection in the repository's "Code security" settings page following the steps outlined in this article.

You can additionally enable push protection for your own personal account, which prevents you from pushing secrets to any public repository on GitHub. For more information, see Push protection for users.

If you're an organization owner, you can enable push protection for multiple repositories at a time using security configurations. For more information, see About enabling security features at scale.

Organization owners, security managers, and repository administrators can also enable push protection for secret scanning via the API. For more information, see REST API endpoints for repositories and expand the "Properties of the security_and_analysis object" section.

Enabling push protection for a repository

  1. On GitHub, navigate to the main page of the repository.

  2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

    Screenshot of a repository header showing the tabs. The "Settings" tab is highlighted by a dark orange outline.

  3. In the "Security" section of the sidebar, click Code security.

  4. Under "Code security", find "GitHub Advanced Security."

  5. Under "Secret scanning", under "Push protection", click Enable.

Further reading