Introduction
GitHub Copilot provides coding suggestions as you type in your editor. You can also ask Copilot coding-related questions, such as how best to code something, how to fix a bug, or how someone else's code works. For full details of what Copilot can do, see What is GitHub Copilot?.
Instructions for using Copilot differ depending on where you are using it. This version of the quickstart is for Visual Studio Code. Click the tabs above for instructions on using Copilot in other environments.
Sign up for GitHub Copilot
If you don't already have access to GitHub Copilot, you can set up a free trial or subscription for Copilot Pro on your personal GitHub account.
Alternatively, you can set up Copilot Free which enables you to enjoy limited access to some of the features of Copilot, without needing to sign up for a subscription. See About GitHub Copilot Free.
For more information about the different plans for GitHub Copilot, see Subscription plans for GitHub Copilot.
Prerequisites
- Latest version of Visual Studio Code. See the Visual Studio Code download page.
- The GitHub Copilot extension - Install this from the Visual Studio Marketplace. For more information, see Set up GitHub Copilot in Visual Studio Code in the Microsoft documentation.
- Sign in to GitHub in Visual Studio Code. If you experience authentication issues, see Troubleshooting issues with GitHub Copilot Chat in IDEs.
Chat with GitHub Copilot
After you've installed the GitHub Copilot extension, you can ask Copilot coding-related questions.
Note
If you have access to GitHub Copilot via your organization, you won't be able to use GitHub Copilot Chat if your organization owner has disabled chat. See Managing policies for Copilot in your organization.
-
Open an existing code file.
-
Open the Chat view from the Activity Bar.
-
At the bottom of the chat view, in the chat input field, type:
explain this file
. -
Press Enter.
Copilot replies in the chat view.
-
In the editor, select one or more lines of code that are not commented.
-
In the chat input field, type:
add comments to these lines
. -
If you like the comments that Copilot suggests, hover over the suggested code in the chat view and click the "Insert at Cursor" icon to replace the selected lines with the suggested code.
Get your first code completion suggestion
The following example uses JavaScript, however other languages will work similarly. GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, but works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++. GitHub Copilot can also assist in query generation for databases, generating suggestions for APIs and frameworks, and can help with infrastructure as code development.
-
Open Visual Studio Code.
-
In Visual Studio Code, create a new JavaScript (*.js) file.
-
In the JavaScript file, type the following function header.
JavaScript function calculateDaysBetweenDates(begin, end) {
function calculateDaysBetweenDates(begin, end) {
GitHub Copilot will automatically suggest an entire function body in grayed text. The exact suggestion may vary.
-
To accept the suggestion, press Tab.
Next steps
- Find out more about Copilot code completion - See Getting code suggestions in your IDE with GitHub Copilot.
- Find out more about GitHub Copilot Chat - See Asking GitHub Copilot questions in your IDE.
- Learn how to write effective prompts - See Prompt engineering for Copilot Chat.
- Use Copilot like a pro - Learn how to write effective prompts for GitHub Copilot. For more information, see Best practices for using GitHub Copilot in VS Code in the Visual Studio Code documentation.
- Get familiar with next edit suggestions - See About next edit suggestions.
- Use Copilot on your mobile device - See Asking GitHub Copilot questions in GitHub Mobile.
- Use Copilot on the command line - See Using GitHub Copilot in the command line.
- Configure Copilot in your editor - You can enable or disable GitHub Copilot from within your editor, and create your own preferred keyboard shortcuts for Copilot. See Configuring GitHub Copilot in your environment.