---
title: "Create or update an environment"
method: PUT
path: "/repos/{owner}/{repo}/environments/{environment_name}"
tags: ["repos"]
---

# Create or update an environment

`PUT /repos/{owner}/{repo}/environments/{environment_name}`

Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "[Environments](/actions/reference/environments#environment-protection-rules)."

> [!NOTE]
> To create or update name patterns that branches must match in order to deploy to this environment, see "[Deployment branch policies](/rest/deployments/branch-policies)."

> [!NOTE]
> To create or update secrets for an environment, see "[GitHub Actions secrets](/rest/actions/secrets)."

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

## Path parameters

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

## Request body

- object, nullable
  - `wait_timer` integer — The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days).
  - `prevent_self_review` boolean — Whether or not a user who created the job is prevented from approving their own job.
  - `reviewers` object[], nullable — The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers. The reviewers must have at least read access to the repository. Only one of the required reviewers needs to approve the job for it to proceed.
    - `type` 'User' | 'Team' — The type of reviewer.
    - `id` integer — The id of the user or team who can review the deployment
  - `deployment_branch_policy` DeploymentBranchPolicySettings, nullable — The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.
    - `protected_branches` boolean, required — Whether only branches with branch protection rules can deploy to this environment. If `protected_branches` is `true`, `custom_branch_policies` must be `false`; if `protected_branches` is `false`, `custom_branch_policies` must be `true`.
    - `custom_branch_policies` boolean, required — Whether only branches that match the specified name patterns can deploy to this environment. If `custom_branch_policies` is `true`, `protected_branches` must be `false`; if `custom_branch_policies` is `false`, `protected_branches` must be `true`.

## Response `200`

Response

- Environment — Details of a deployment environment
  - `id` integer, required — The id of the environment.
  - `node_id` string, required
  - `name` string, required — The name of the environment.
  - `url` string, required
  - `html_url` string, required
  - `created_at` string, date-time, required — The time that the environment was created, in ISO 8601 format.
  - `updated_at` string, date-time, required — The time that the environment was last updated, in ISO 8601 format.
  - `protection_rules` union[] — Built-in deployment protection rules for the environment.
    - union
      - object
        - `id` integer, required
        - `node_id` string, required
        - `type` string, required
        - `wait_timer` integer — The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days).
      - object
        - `id` integer, required
        - `node_id` string, required
        - `prevent_self_review` boolean — Whether deployments to this environment can be approved by the user who created the deployment.
        - `type` string, required
        - `reviewers` object[] — The people or teams that may approve jobs that reference the environment. You can list up to six users or teams as reviewers. The reviewers must have at least read access to the repository. Only one of the required reviewers needs to approve the job for it to proceed.
          - `type` 'User' | 'Team' — The type of reviewer.
          - `reviewer` union
            - SimpleUser — A GitHub user.
              - …
            - Team — Groups of organization members that gives permissions on specified repositories.
              - …
      - object
        - `id` integer, required
        - `node_id` string, required
        - `type` string, required
  - `deployment_branch_policy` DeploymentBranchPolicySettings, nullable — The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.
    - `protected_branches` boolean, required — Whether only branches with branch protection rules can deploy to this environment. If `protected_branches` is `true`, `custom_branch_policies` must be `false`; if `protected_branches` is `false`, `custom_branch_policies` must be `true`.
    - `custom_branch_policies` boolean, required — Whether only branches that match the specified name patterns can deploy to this environment. If `custom_branch_policies` is `true`, `protected_branches` must be `false`; if `custom_branch_policies` is `false`, `protected_branches` must be `true`.

## Other responses

- `422` — Validation error when the environment name is invalid or when `protected_branches` and `custom_branch_policies` in `deployment_branch_policy` are set to the same value

---

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