{"meta":{"title":"Конечные точки REST API для политик ветви развертывания","intro":"Используйте REST API для управления настраиваемыми политиками ветви развертывания.","product":"REST API","breadcrumbs":[{"href":"/ru/rest","title":"REST API"},{"href":"/ru/rest/deployments","title":"Развертывания"},{"href":"/ru/rest/deployments/branch-policies","title":"Политики ветвей развертывания"}],"documentType":"article"},"body":"# Конечные точки REST API для политик ветви развертывания\n\nИспользуйте REST API для управления настраиваемыми политиками ветви развертывания.\n\n## Сведения о политиках ветви развертывания\n\nС помощью REST API можно указать пользовательские шаблоны имен, которые должны соответствовать ветвям для развертывания в среде. Необходимо задать свойство `deployment_branch_policy.custom_branch_policies` для среды, чтобы разрешить `true` использовать эти конечные точки. Сведения об обновлении среды см. в `deployment_branch_policy` разделе [Конечные точки REST API для сред развертывания](/ru/rest/deployments/environments#create-or-update-an-environment).\n\nДополнительные сведения об ограничении развертываний среды в определенных ветвях см. в разделе [Управление средами для развертывания](/ru/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments).\n\n> \\[!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.\n\n## List deployment branch policies\n\n```\nGET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies\n```\n\nLists the deployment branch policies for an environment.\nAnyone with read access to the repository can use this endpoint.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`environment_name`** (string) (required)\n  The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.\n\n* **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n* **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies\n```\n\n**Response schema (Status: 200):**\n\n* `total_count`: required, integer\n* `branch_policies`: required, array of `Deployment branch policy`:\n  * `id`: integer\n  * `node_id`: string\n  * `name`: string\n  * `type`: string, enum: `branch`, `tag`\n\n## Create a deployment branch policy\n\n```\nPOST /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies\n```\n\nCreates a deployment branch or tag policy for an environment.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`environment_name`** (string) (required)\n  The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.\n\n#### Body parameters\n\n* **`name`** (string) (required)\n  The name pattern that branches or tags must match in order to deploy to the environment.\n  Wildcard characters will not match /. For example, to match branches that begin with release/ and contain an additional single slash, use release/*/*.\n  For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.\n\n* **`type`** (string)\n  Whether this rule targets a branch or tag\n  Can be one of: `branch`, `tag`\n\n### HTTP response status codes\n\n* **200** - OK\n\n* **303** - Response if the same branch name pattern already exists\n\n* **404** - Not Found or deployment\\_branch\\_policy.custom\\_branch\\_policies property for the environment is set to false\n\n### Code examples\n\n#### Example of a wildcard name pattern\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies \\\n  -d '{\n  \"name\": \"release/*\"\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `id`: integer\n* `node_id`: string\n* `name`: string\n* `type`: string, enum: `branch`, `tag`\n\n#### Example of a single branch name pattern\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies \\\n  -d '{\n  \"name\": \"main\",\n  \"type\": \"branch\"\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `id`: integer\n* `node_id`: string\n* `name`: string\n* `type`: string, enum: `branch`, `tag`\n\n#### Example of a single tag name pattern\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies \\\n  -d '{\n  \"name\": \"v1\",\n  \"type\": \"tag\"\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `id`: integer\n* `node_id`: string\n* `name`: string\n* `type`: string, enum: `branch`, `tag`\n\n## Get a deployment branch policy\n\n```\nGET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}\n```\n\nGets a deployment branch or tag policy for an environment.\nAnyone with read access to the repository can use this endpoint.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`environment_name`** (string) (required)\n  The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.\n\n* **`branch_policy_id`** (integer) (required)\n  The unique identifier of the branch policy.\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a deployment branch policy](#create-a-deployment-branch-policy).\n\n## Update a deployment branch policy\n\n```\nPUT /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}\n```\n\nUpdates a deployment branch or tag policy for an environment.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`environment_name`** (string) (required)\n  The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.\n\n* **`branch_policy_id`** (integer) (required)\n  The unique identifier of the branch policy.\n\n#### Body parameters\n\n* **`name`** (string) (required)\n  The name pattern that branches must match in order to deploy to the environment.\n  Wildcard characters will not match /. For example, to match branches that begin with release/ and contain an additional single slash, use release/*/*.\n  For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PUT \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID \\\n  -d '{\n  \"name\": \"release/*\"\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a deployment branch policy](#create-a-deployment-branch-policy).\n\n## Delete a deployment branch policy\n\n```\nDELETE /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}\n```\n\nDeletes a deployment branch or tag policy for an environment.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`environment_name`** (string) (required)\n  The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.\n\n* **`branch_policy_id`** (integer) (required)\n  The unique identifier of the branch policy.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID\n```\n\n**Response schema (Status: 204):**"}