# Merge a pull request

From **GitHub v3 REST API**.

`PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge`

This endpoint triggers [notifications](https://docs.github.com/enterprise-server@3.0/github/managing-subscriptions-and-notifications-on-github/about-notifications). Creating content too quickly using this endpoint may result in secondary rate limiting. See "[Secondary rate limits](https://docs.github.com/enterprise-server@3.0/rest/overview/resources-in-the-rest-api#secondary-rate-limits)" and "[Dealing with secondary rate limits](https://docs.github.com/enterprise-server@3.0/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details.

## Parameters

### `owner`

- Location: path
- Required: true
- Type: `string`

### `repo`

- Location: path
- Required: true
- Type: `string`

### `pull_number`

- Location: path
- Required: true
- Type: `integer`

## Request body

- Required: false
### `application/json`

- Type: `object`
- Nullable: true

```json
{"nullable":true,"properties":{"commit_message":{"description":"Extra detail to append to automatic commit message.","type":"string"},"commit_title":{"description":"Title for the automatic commit message.","type":"string"},"merge_method":{"description":"Merge method to use. Possible values are `merge`, `squash` or `rebase`. Default is `merge`.","enum":["merge","squash","rebase"],"type":"string"},"sha":{"description":"SHA that pull request head must match to allow merge.","type":"string"}},"type":"object"}
```

## Responses

### `200`

if merge was successful

### `application/json`

- Type: `object`

Pull Request Merge Result

```json
{
  "merged": true,
  "message": "Pull Request successfully merged",
  "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
```

```json
{"description":"Pull Request Merge Result","properties":{"merged":{"type":"boolean"},"message":{"type":"string"},"sha":{"type":"string"}},"required":["merged","message","sha"],"title":"Pull Request Merge Result","type":"object"}
```

### `403`

Forbidden

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `404`

Resource not found

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `405`

Method Not Allowed if merge cannot be performed

### `application/json`

- Type: `object`

```json
{
  "message": "Pull Request is not mergeable"
}
```

```json
{"properties":{"documentation_url":{"type":"string"},"message":{"type":"string"}},"type":"object"}
```

### `409`

Conflict if sha was provided and pull request head did not match

### `application/json`

- Type: `object`

```json
{
  "message": "Head branch was modified. Review and try the merge again."
}
```

```json
{"properties":{"documentation_url":{"type":"string"},"message":{"type":"string"}},"type":"object"}
```

### `422`

Validation failed

### `application/json`

- Type: `object`

Validation Error

```json
{"description":"Validation Error","properties":{"documentation_url":{"type":"string"},"errors":{"items":{"properties":{"code":{"type":"string"},"field":{"type":"string"},"index":{"type":"integer"},"message":{"type":"string"},"resource":{"type":"string"},"value":{"oneOf":[{"nullable":true,"type":"string"},{"nullable":true,"type":"integer"},{"items":{"type":"string"},"nullable":true,"type":"array"}]}},"required":["code"],"type":"object"},"type":"array"},"message":{"type":"string"}},"required":["message","documentation_url"],"title":"Validation Error","type":"object"}
```

## Request examples

### cURL

```shell
curl --request PUT \
  --url {protocol}://{hostname}/api/v3/repos/{owner}/{repo}/pulls/{pull_number}/merge \
  --header 'content-type: application/json' \
  --data '{
  "commit_message": "string",
  "commit_title": "string",
  "merge_method": "string",
  "sha": "string"
}'
```
