---
title: "Commit an autofix for a code scanning alert"
method: POST
path: "/repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/autofix/commits"
tags: ["code-scanning"]
---

# Commit an autofix for a code scanning alert

`POST /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/autofix/commits`

## Request

- Base URL: `https://api.github.com`
- URL: `https://api.github.com/repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/autofix/commits`
- Auth: none declared

Commits an autofix for a code scanning alert from the repository's default branch.

If an autofix is committed as a result of this request, then this endpoint will return a 201 Created response.

OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint with private or public repositories, or the `public_repo` scope to use this endpoint with only public repositories.

## Path parameters

- `owner` string, required
- `repo` string, required
- `alert_number` integer, required: The security alert number.

## Request body

- CodeScanningAutofixCommits, nullable: Commit an autofix for a code scanning alert
  - `target_ref` string: The Git reference of target branch for the commit. Branch needs to already exist. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.
  - `message` string: Commit message to be used.

## Response `201`

Created

- CodeScanningAutofixCommitsResponse
  - `target_ref` string: The Git reference of target branch for the commit. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.
  - `sha` string: SHA of commit with autofix.

## Other responses

- `400`: Bad Request
- `403`: Response if the repository is archived or if GitHub Advanced Security is not enabled for this repository
- `404`: Resource not found
- `422`: Unprocessable Entity
- `503`: Service unavailable

---

[API](https://skmtc.dev/github/apis/enterprise-cloud.md) · [All operations](https://skmtc.dev/github/apis/enterprise-cloud/llms.txt) · [OpenAPI document](https://skmtc.dev/github/apis/enterprise-cloud/revisions/998ae512e4cd?raw)
