How to delete environments on GitHub

14 May, 2020

There is no way you can delete a deployment environment using GitHub UI or API. But you can delete all the deployments for one environment, and then it will be gone.

Create a new security token with repo_deployments allowed: https://github.com/settings/tokens.

In the scripts below, replace $TOKEN with the new token, $USER and $REPO with your data, and $DEPLOYMENT_ID with the id of deployment you want to delete.

Get a list of all deployments

curl -u $USER:$TOKEN https://api.github.com/repos/$USER/$REPO/deployments

Make deployment inactive

curl -u $USER:$TOKEN\
  -X POST\
  -H "Content-Type: application/json"\
  -H "Accept: application/vnd.github.ant-man-preview+json"\
  -d '{"state": "inactive"}'\
  https://api.github.com/repos/$USER/$REPO/deployments/$DEPLOYMENT_ID/statuses

Delete deployment

curl -u $USER:$TOKEN\
  -X DELETE\
  https://api.github.com/repos/$USER/$REPO/deployments/$DEPLOYMENT_ID