# 使用与 REST API 相关的推送保护

了解用于当 GitHub 在 API 请求内容中检测到机密时使用 REST API 取消阻止推送到 secret scanning 的选项。

## 关于 REST API 的推送防护机制

推送保护通过阻止包含支持的机密的推送，防止你无意将机密提交到存储库。

REST API 中的“创建 blob”和“创建或更新文件内容”终结点包括推送保护。 请参阅 [Git Blob 的 REST API 端点](/zh/enterprise-server@3.22/rest/git/blobs?apiVersion=2022-11-28#create-a-blob) 和 [存储库内容的 REST API 终结点](/zh/enterprise-server@3.22/rest/repos/contents?apiVersion=2022-11-28#create-or-update-file-contents)。

如果对内容包括受支持的机密的这些终结点发出请求，REST API 将返回 409 错误，指示检测到机密。

可通过以下任一方法解决该错误：

* 在重试之前，从 API 请求的内容中**删除**机密。
* **创建推送保护绕过**：你可以使用“创建推送保护绕过”终结点绕过推送保护。 有关详细信息，请参阅“[适用于机密扫描的 REST API 终结点](/zh/enterprise-server@3.22/rest/secret-scanning/secret-scanning?apiVersion=2022-11-28#create-a-push-protection-bypass)”。

## 延伸阅读

* [从命令行使用推送保护](/zh/enterprise-server@3.22/code-security/how-tos/secure-your-secrets/work-with-leak-prevention/push-protection-on-the-command-line)
* [通过 GitHub UI 使用推送保护功能](/zh/enterprise-server@3.22/code-security/how-tos/secure-your-secrets/work-with-leak-prevention/push-protection-in-the-github-ui)