Skip to main content

Deleting a codespace

You can delete a codespace you no longer need.

GitHub Codespaces 可用于使用 GitHub Team 或 GitHub Enterprise Cloud 的组织。 GitHub Codespaces 也可作为受限的 beta 版本提供给使用 GitHub Free 和 GitHub Pro 计划的个人用户。 有关详细信息,请参阅“GitHub 的产品”。

There are costs associated with storing codespaces. You should therefore delete any codespaces you no longer need. For more information, see "About billing for GitHub Codespaces."

可以创建的 codespace 数量和可以同时运行的 codespace 数量受到限制。 这些限制因多种因素而异。 如果达到最大 codespace 数并尝试创建另一个 codespace,则会显示一条消息,告知你必须删除现有 codespace,然后才能创建新的 codespace。

Deleting a codespace

  1. Navigate to the "Your codespaces" page at github.com/codespaces.

  2. To the right of the codespace you want to delete, click , then click Delete

    Delete button

如你当前未在 codespace 中工作,可从 VS Code 内删除 codespace。

  1. 在 VS Code 中,从左侧边栏单击“远程 Explorer”图标。

    Visual Studio Code 中的 Remote Explorer 图标

    Note: If the Remote Explorer is not displayed in the Activity Bar:

    1. Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
    2. Type: codespaces.
    3. Click Codespaces: Details.
  2. 在“GitHub Codespaces”下,右键点击你要删除的 codespace。

  3. 单击“删除 codespace”。

    在 GitHub 中删除代码空间

若要详细了解 GitHub CLI,请参阅“关于 GitHub CLI”。

To delete a codespace use the gh codespace delete subcommand and then choose a codespace from the list that's displayed.

gh codespace delete

If you have unsaved changes, you'll be prompted to confirm deletion. You can use the --force flag to force deletion, avoiding this prompt.

For more information about this command, see the GitHub CLI manual.

Bulk deleting codespaces

You can use GitHub CLI to delete several or all of your codespaces with a single command. For more information, click the GitHub CLI tab near the top of this page.

You can use GitHub CLI to delete several or all of your codespaces with a single command. For more information, click the GitHub CLI tab near the top of this page.

You can delete several or all of your codespaces with a single command, using gh codespace delete followed by one of these flags:

--all - Delete all of your codespaces.

--repo REPOSITORY - Delete all of your codespaces for this repository. Or use together with the --days flag to filter by age of the codespace.

--days NUMBER - Delete all of your codespaces that are older than the specified number of days. Can be used together with the --repo flag.

By default you are prompted to confirm deletion of any codespaces that contain unsaved changes. You can use the --force flag to skip this confirmation.

Example

Delete all of the codespaces for the octo-org/octo-repo repository that you created more than 7 days ago.

gh cs delete --repo octo-org/octo-repo --days 7

Deleting codespaces in your organization

As an organization owner, you can use GitHub CLI to delete any codespace in your organization.

For more information, click the "GitHub CLI" tab near the top of this page.

For more information, click the "GitHub CLI" tab near the top of this page.

  1. Enter one of these commands to display a list of codespaces.

    • gh codespace delete --org ORGANIZATION - Lists the current codespaces in the specified organization.
    • gh codespace delete --org ORGANIZATION --user USER - Lists only those codespaces created by the specified user. You must be an owner of the specified organization.
  2. In the list of codespaces, navigate to the codespace you want to delete.

  3. To delete the selected codespace press Enter.

    If the codespace contains unsaved changes you will be prompted to confirm deletion.

You can also use the REST API to delete codespaces for your organization. For more information, see "Codespaces organizations."

Further reading