Introduction
GitHub Copilot is an AI pair programmer. You can use GitHub Copilot to get suggestions for whole lines or entire functions right inside your editor.
This guide will show you how to sign up for GitHub Copilot, install the GitHub Copilot extension in Visual Studio Code, and get your first suggestion. For more information on GitHub Copilot, see "About GitHub Copilot." For more in-depth information on how to use GitHub Copilot in a variety of environments, see "Getting Started."
Prerequisites
- GitHub Copilot 供经过验证的学生和开放源代码维护者免费使用。
- 如果你不是学生或开放源代码维护者,可以在一次性 60 天试用版中免费试用 GitHub Copilot。 免费试用后,需要付费订阅才能继续使用。 必须提供账单信息才能开始免费试用。 有关详细信息,请参阅“关于 GitHub Copilot 的计费”。
- To use GitHub Copilot in Visual Studio Code, you must have Visual Studio Code installed. For more information, see the Visual Studio Code documentation.
Signing up for GitHub Copilot
在开始使用 GitHub Copilot 之前,需要设置免费试用或订阅。
-
在任何页面的右上角,单击个人资料照片,然后单击“设置”。

-
在边栏的“代码、规划和自动化”部分,单击“ GitHub Copilot”。
-
在 GitHub Copilot 设置页面上,单击“启用 GitHub Copilot”。

-
选择要按月还是按年付款,然后单击“继续访问 Copilot”。
- 如果个人帐户符合免费 GitHub Copilot 订阅(而不是试用)的条件,将自动转到步骤 6。

-
按照步骤确认付款详细信息,然后单击“提交”。
-
选择首选项,然后单击“保存并开始”。

可以稍后通过返回到 GitHub Copilot 设置来更改这些首选项。 有关详细信息,请参阅“在 Visual Studio Code 中配置 GitHub Copilot”。
Installing the GitHub Copilot extension for Visual Studio Code
To use GitHub Copilot, you must first install the Visual Studio Code extension.
- In the Visual Studio Code Marketplace, go to the GitHub Copilot extension page and click Install.

- A popup will appear, asking to open Visual Studio Code. Click Open Visual Studio Code.
- In the "Extension: GitHub Copilot" tab in Visual Studio Code, click Install.

- If you have not previously authorized Visual Studio Code in your GitHub account, you will be prompted to sign in to GitHub in Visual Studio Code.
- If you have previously authorized Visual Studio Code in your GitHub account, GitHub Copilot will be automatically authorized.

- If you have previously authorized Visual Studio Code in your GitHub account, GitHub Copilot will be automatically authorized.
- In your browser, GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, click Authorize Visual Studio Code.
- In Visual Studio Code, in the "Visual Studio Code" dialogue box, to confirm the authentication, click Open.
Getting your first suggestion
Note: If you have duplication detection enabled for GitHub Copilot, you may receive limited suggestions, or no suggestions, when using the code examples provided. As an alternative, you can start by typing your own code to see suggestions from GitHub Copilot. For more information on duplication detection, see "Enabling or disabling duplication detection."
GitHub Copilot 为多种语言和各种框架提供建议,但尤其适用于 Python、JavaScript、TypeScript、Ruby、Go、C# 和 C++。 The following samples are in JavaScript, but other languages will work similarly.
-
Open Visual Studio Code.
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
在 JavaScript 文件中,键入以下函数标头。
JavaScript function calculateDaysBetweenDates(begin, end) {GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.

-
要接受建议,请按 Tab。
Next Steps
You successfully installed GitHub Copilot and received your first suggestion, but that's just the beginning! Here are some helpful resources for taking your next steps with GitHub Copilot.
- Getting Started: You've learned how to get your first suggestion in Visual Studio Code. These guides show you how to set up and navigate the various functions of GitHub Copilot across all of the supported environments.
- GitHub Copilot: See practical examples of how GitHub Copilot can help you work.
- Configuring GitHub Copilot: These guides provide details on how to configure GitHub Copilot to your personal preferences.