---
title: "Create a deployment"
method: POST
path: "/repos/{owner}/{repo}/deployments"
tags: ["repos"]
---

# Create a deployment

`POST /repos/{owner}/{repo}/deployments`

Deployments offer a few configurable parameters with certain defaults.

The `ref` parameter can be any named branch, tag, or SHA. At GitHub we often deploy branches and verify them
before we merge a pull request.

The `environment` parameter allows deployments to be issued to different runtime environments. Teams often have
multiple environments for verifying their applications, such as `production`, `staging`, and `qa`. This parameter
makes it easier to track which environments have requested deployments. The default environment is `production`.

The `auto_merge` parameter is used to ensure that the requested ref is not behind the repository's default branch. If
the ref _is_ behind the default branch for the repository, we will attempt to merge it for you. If the merge succeeds,
the API will return a successful merge commit. If merge conflicts prevent the merge from succeeding, the API will
return a failure response.

By default, [commit statuses](https://docs.github.com/rest/commits/statuses) for every submitted context must be in a `success`
state. The `required_contexts` parameter allows you to specify a subset of contexts that must be `success`, or to
specify contexts that have not yet been submitted. You are not required to use commit statuses to deploy. If you do
not require any contexts or create any commit statuses, the deployment will always succeed.

The `payload` parameter is available for any extra information that a deployment system might need. It is a JSON text
field that will be passed on when a deployment event is dispatched.

The `task` parameter is used by the deployment system to allow different execution paths. In the web world this might
be `deploy:migrations` to run schema changes on the system. In the compiled world this could be a flag to compile an
application with debugging enabled.

Merged branch response:

You will see this response when GitHub automatically merges the base branch into the topic branch instead of creating
a deployment. This auto-merge happens when:
*   Auto-merge option is enabled in the repository
*   Topic branch does not include the latest changes on the base branch, which is `master` in the response example
*   There are no merge conflicts

If there are no new commits in the base branch, a new request to create a deployment should give a successful
response.

Merge conflict response:

This error happens when the `auto_merge` option is enabled and when the default branch (in this case `master`), can't
be merged into the branch that's being deployed (in this case `topic-branch`), due to merge conflicts.

Failed commit status checks:

This error happens when the `required_contexts` parameter indicates that one or more contexts need to have a `success`
status for the commit to be deployed, but one or more of the required contexts do not have a state of `success`.

OAuth app tokens and personal access tokens (classic) need the `repo` or `repo_deployment` scope to use this endpoint.

## Path parameters

- `owner` string, required
- `repo` string, required

## Request body

- object
  - `ref` string, required — The ref to deploy. This can be a branch, tag, or SHA.
  - `task` string — Specifies a task to execute (e.g., `deploy` or `deploy:migrations`).
  - `auto_merge` boolean — Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch.
  - `required_contexts` string[] — The [status](https://docs.github.com/rest/commits/statuses) contexts to verify against commit status checks. If you omit this parameter, GitHub verifies all unique contexts before creating a deployment. To bypass checking entirely, pass an empty array. Defaults to all unique contexts.
  - `payload` union
    - object
    - string — JSON payload with extra information about the deployment.
  - `environment` string — Name for the target deployment environment (e.g., `production`, `staging`, `qa`).
  - `description` string, nullable — Short description of the deployment.
  - `transient_environment` boolean — Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future. Default: `false`
  - `production_environment` boolean — Specifies if the given environment is one that end-users directly interact with. Default: `true` when `environment` is `production` and `false` otherwise.

## Response `201`

Response

- Deployment — A request for a specific ref(branch,sha,tag) to be deployed
  - `url` string, uri, required
  - `id` integer, required — Unique identifier of the deployment
  - `node_id` string, required
  - `sha` string, required
  - `ref` string, required — The ref to deploy. This can be a branch, tag, or sha.
  - `task` string, required — Parameter to specify a task to execute
  - `payload` union, required
    - object
    - string
  - `original_environment` string
  - `environment` string, required — Name for the target deployment environment.
  - `description` string, nullable, required
  - `creator` NullableSimpleUser, nullable, required — A GitHub user.
    - `name` string, nullable
    - `email` string, nullable
    - `login` string, required
    - `id` integer, required
    - `node_id` string, required
    - `avatar_url` string, uri, required
    - `gravatar_id` string, nullable, required
    - `url` string, uri, required
    - `html_url` string, uri, required
    - `followers_url` string, uri, required
    - `following_url` string, required
    - `gists_url` string, required
    - `starred_url` string, required
    - `subscriptions_url` string, uri, required
    - `organizations_url` string, uri, required
    - `repos_url` string, uri, required
    - `events_url` string, required
    - `received_events_url` string, uri, required
    - `type` string, required
    - `site_admin` boolean, required
    - `starred_at` string
    - `user_view_type` string
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required
  - `statuses_url` string, uri, required
  - `repository_url` string, uri, required
  - `transient_environment` boolean — Specifies if the given environment is will no longer exist at some point in the future. Default: false.
  - `production_environment` boolean — Specifies if the given environment is one that end-users directly interact with. Default: false.
  - `performed_via_github_app` NullableIntegration, nullable — GitHub apps are a new way to extend GitHub. They can be installed directly on organizations and user accounts and granted access to specific repositories. They come with granular permissions and built-in webhooks. GitHub apps are first class actors within GitHub.
    - `id` integer, required — Unique identifier of the GitHub app
    - `slug` string — The slug name of the GitHub app
    - `node_id` string, required
    - `client_id` string
    - `owner` union, required
      - SimpleUser — A GitHub user.
        - `name` string, nullable
        - `email` string, nullable
        - `login` string, required
        - `id` integer, required
        - `node_id` string, required
        - `avatar_url` string, uri, required
        - `gravatar_id` string, nullable, required
        - `url` string, uri, required
        - `html_url` string, uri, required
        - `followers_url` string, uri, required
        - `following_url` string, required
        - `gists_url` string, required
        - `starred_url` string, required
        - `subscriptions_url` string, uri, required
        - `organizations_url` string, uri, required
        - `repos_url` string, uri, required
        - `events_url` string, required
        - `received_events_url` string, uri, required
        - `type` string, required
        - `site_admin` boolean, required
        - `starred_at` string
        - `user_view_type` string
      - Enterprise — An enterprise on GitHub.
        - `description` string, nullable — A short description of the enterprise.
        - `html_url` string, uri, required
        - `website_url` string, uri, nullable — The enterprise's website URL.
        - `id` integer, required — Unique identifier of the enterprise
        - `node_id` string, required
        - `name` string, required — The name of the enterprise.
        - `slug` string, required — The slug url identifier for the enterprise.
        - `created_at` string, date-time, nullable, required
        - `updated_at` string, date-time, nullable, required
        - `avatar_url` string, uri, required
    - `name` string, required — The name of the GitHub app
    - `description` string, nullable, required
    - `external_url` string, uri, required
    - `html_url` string, uri, required
    - `created_at` string, date-time, required
    - `updated_at` string, date-time, required
    - `permissions` object, required — The set of permissions for the GitHub app
      - `issues` string
      - `checks` string
      - `metadata` string
      - `contents` string
      - `deployments` string
    - `events` string[], required — The list of events for the GitHub app. Note that the `installation_target`, `security_advisory`, and `meta` events are not included because they are global events and not specific to an installation.
    - `installations_count` integer — The number of installations associated with the GitHub app. Only returned when the integration is requesting details about itself.

## Other responses

- `202` — Merged branch response
- `409` — Conflict when there is a merge conflict or the commit's status checks failed
- `422` — Validation failed, or the endpoint has been spammed.

---

[API](https://skmtc.net/github/apis/rest-api.md) · [All operations](https://skmtc.net/github/apis/rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/github/rest-api/versions/80850db290cd/schema)
