About GitHub Codespaces in Visual Studio Code
You can use your local install of Visual Studio Code to create, manage, work in, and delete codespaces. To use GitHub Codespaces in VS Code, you need to install the Codespaces extension. For more information on setting up Codespaces in VS Code, see "Prerequisites."
By default, if you create a new codespace on GitHub.com, it will open in the browser. If you would prefer to open any new codespaces in VS Code automatically, you can set your default editor to be VS Code. For more information, see "Setting your default editor for GitHub Codespaces."
If you prefer to work in the browser, but want to continue using your existing VS Code extensions, themes, and shortcuts, you can turn on Settings Sync. For more information, see "Personalizing GitHub Codespaces for your account."
Prerequisites
To develop in a codespace directly in VS Code, you must install and sign into the Codespaces extension with your GitHub credentials. The Codespaces extension requires VS Code October 2020 Release 1.51 or later.
Use the Visual Studio Code Marketplace to install the Codespaces extension. For more information, see Extension Marketplace in the VS Code documentation.
-
In VS Code, in the left sidebar, click the Remote Explorer icon.

Note: If the Remote Explorer is not displayed in the Activity Bar:
- Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
- Type:
codespaces. - Click Codespaces: Details.
-
Click Sign in to view GitHub....

-
To authorize VS Code to access your account on GitHub, click Allow.
-
Sign in to GitHub to approve the extension.
-
In VS Code, in the left sidebar, click the Remote Explorer icon.

Note: If the Remote Explorer is not displayed in the Activity Bar:
- Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
- Type:
codespaces. - Click Codespaces: Details.
-
Use the "REMOTE EXPLORER" drop-down, then click GitHub Codespaces.

-
Click Sign in to view Codespaces....

-
To authorize VS Code to access your account on GitHub, click Allow.
-
Sign in to GitHub to approve the extension.
Creating a codespace in VS Code
将 GitHub.com 上的帐户连接到 GitHub Codespaces 扩展后,可以创建新的 codespace。 有关 GitHub Codespaces 扩展的详细信息,请参阅 VS Code Marketplace 市场。
注意:目前,VS Code 不允许在创建 codespace 时选择开发容器配置。 如果要选择特定的开发容器配置,请使用 GitHub Web 界面来创建 codespace。 有关详细信息,请单击此页面顶部的“Web 浏览器”选项卡。
-
In VS Code, in the left sidebar, click the Remote Explorer icon.

Note: If the Remote Explorer is not displayed in the Activity Bar:
- Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
- Type:
codespaces. - Click Codespaces: Details.
-
单击“添加”图标:。

-
键入要在其中开发的存储库的名称,然后将其选中。

-
单击要在其中开发的分支。

-
如果系统提示选择开发容器配置文件,请从列表中选择一个文件。

-
选择你要使用的机器类型。

注意:可供选择的计算机类型可能会受为组织配置的策略或存储库的计算机类型最低规范的限制。 有关详细信息,请参阅“限制对计算机类型的访问”和“为代码空间计算机设置最低规范”。
Opening a codespace in VS Code
-
In VS Code, in the left sidebar, click the Remote Explorer icon.

Note: If the Remote Explorer is not displayed in the Activity Bar:
- Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
- Type:
codespaces. - Click Codespaces: Details.
-
Under "Codespaces", click the codespace you want to develop in.
-
Click the Connect to Codespace icon.

Changing the machine type in VS Code
通常,你可以在选择的远程机器上运行 codespace,从 2 核到 32 核。 每种类型都有不同的资源水平和不同的计费等级。 有关信息,请参阅“关于 GitHub Codespaces 的计费”。
默认情况下,创建 codespace 时将使用具有最低有效资源的计算机类型。 You can change the machine type of your codespace at any time.
-
In VS Code, open the Command Palette (
shift command P/shift control P). -
Search for and select "Codespaces: Change Machine Type."

-
Click the codespace that you want to change.

-
Choose the machine type you want to use.
Note: 可供选择的计算机类型可能会受为组织配置的策略或存储库的计算机类型最低规范的限制。 有关详细信息,请参阅“限制对计算机类型的访问”和“为代码空间计算机设置最低规范”。
-
If the codespace is currently running, a message is displayed asking if you would like to restart and reconnect to your codespace now.
Click Yes if you want to change the machine type used for this codespace immediately.
If you click No, or if the codespace is not currently running, the change will take effect the next time the codespace restarts.
Deleting a codespace in VS Code
如你当前未在 codespace 中工作,可从 VS Code 内删除 codespace。
-
In VS Code, in the left sidebar, click the Remote Explorer icon.

Note: If the Remote Explorer is not displayed in the Activity Bar:
- Access the Command Palette. For example, by pressing Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux).
- Type:
codespaces. - Click Codespaces: Details.
-
在“GitHub Codespaces”下,右键点击你要删除的 codespace。
-
单击“删除 codespace”。

Switching to the Insiders build of VS Code
You can use the Insiders Build of VS Code within Codespaces.
-
In bottom left of your Codespaces window, select Settings.
-
From the list, select "Switch to Insiders Version".

-
Once selected, Codespaces will continue to open in Insiders Version.

