100% found this document useful (1 vote)
407 views

Getting Started With GitHub Copilot in VS Code (Docs Github Com)

GitHub Copilot is an AI assistant that provides code completions and suggestions as you work in Visual Studio Code. This document outlines how to install the GitHub Copilot extension for Visual Studio Code and begin using it to receive suggestions for code, comments, and frameworks like Express.js. It also describes how to view alternative suggestions and enable or disable Copilot.

Uploaded by

Owen Perrin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
407 views

Getting Started With GitHub Copilot in VS Code (Docs Github Com)

GitHub Copilot is an AI assistant that provides code completions and suggestions as you work in Visual Studio Code. This document outlines how to install the GitHub Copilot extension for Visual Studio Code and begin using it to receive suggestions for code, comments, and frameworks like Express.js. It also describes how to view alternative suggestions and enable or disable Copilot.

Uploaded by

Owen Perrin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

docs.github.

com
/en/copilot/getting-started-with-github-copilot/getting-started-with-github-copilot-in-visual-studio-code

Getting started with GitHub Copilot in Visual Studio Code

Learn how to install GitHub Copilot in Visual Studio Code, and start seeing suggestions as you write
comments and code.

GitHub Copilot is available to GitHub customers with a personal account on GitHub.com and GitHub
Enterprise Cloud organizations owned by an enterprise account.

GitHub Copilot is free to use for verified students, teachers, and maintainers of popular open source
projects. If you are not a student, teacher, or maintainer of a popular open source project, you can try
GitHub Copilot for free with a one-time 60-day trial. After the free trial, you will need a paid subscription
for continued use. For more information, see "About billing for GitHub Copilot."

Try GitHub Copilot

About GitHub Copilot and Visual Studio Code


GitHub Copilot provides autocomplete-style suggestions from an AI pair programmer as you code. For
more information, see "About GitHub Copilot".

If you use Visual Studio Code, you can view and incorporate suggestions from GitHub Copilot directly
within the editor. This guide demonstrates how to use GitHub Copilot within Visual Studio Code for
macOS, Windows, or Linux.

Prerequisites
To use GitHub Copilot you must have an active GitHub Copilot subscription. For more information,
see "About billing for 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 download page.

Installing the Visual Studio Code extension


To use GitHub Copilot, you must first install the Visual Studio Code extension.

1/5
1. In the Visual Studio Code Marketplace, go to the GitHub Copilot extension page and click Install.

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

4. 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 for your account on GitHub, GitHub
Copilot will be automatically authorized.

5. In your browser, GitHub will request the necessary permissions for GitHub Copilot. To approve
these permissions, click Authorize Visual Studio Code.
6. In Visual Studio Code, in the "Visual Studio Code" dialog box, to confirm the authentication, click
Open.

Seeing your first suggestion


GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, but
Note:especially
works If you havewell
duplication detection
for Python, enabled
JavaScript, for GitHub
TypeScript, Copilot,
Ruby, youand
Go, C# mayC++.
receive
The limited suggestions,
following samples
or no
are suggestions,
in JavaScript, when
but otherusing the code
languages willexamples provided. As an alternative, you can start by typing
work similarly.
your own code to see suggestions from GitHub Copilot. For more information on duplication detection,
see1."Enabling
In Visual or
Studio Code,duplication
disabling create a new JavaScript (*.js) file.
detection."

2/5
2. In the JavaScript file, type the following function header. GitHub Copilot will automatically suggest
an entire function body in grayed text, as shown below. The exact suggestion may vary.

function calculateDaysBetweenDates(begin, end) {

3. To accept the suggestion, press Tab.

Seeing alternative suggestions


For any given input, GitHub Copilot may offer multiple suggestions. You can select which suggestion to
use, or reject all suggestions.

1. In Visual Studio Code, create a new JavaScript (*.js) file.

2. In the JavaScript file, type the following function header. GitHub Copilot will show you a suggestion.

function calculateDaysBetweenDates(begin, end) {

3. Optionally, you can see alternative suggestions, if any are available.

OS See next suggestion See previous suggestion


macOS Option (⌥) or Alt+] Option (⌥) or Alt+[
Windows Alt+] Alt+[
Linux Alt+] Alt+[

4. Alternatively, you can hover over the suggestion to see the GitHub Copilot command palette for
choosing suggestions.

5. To accept a suggestion, press Tab. To reject all suggestions, press Esc.

Seeing multiple suggestions in a new tab


You may not want any of the initial suggestions GitHub Copilot offers. You can use a keyboard shortcut to
prompt GitHub Copilot to show you multiple suggestions in a new tab.

1. In Visual Studio Code, create a new JavaScript (*.js) file.


2. In the JavaScript file, type the following function header. GitHub Copilot will show you a suggestion.

3/5
function calculateDaysBetweenDates(begin, end) {

3. To open a new tab with multiple additional options, press Ctrl+Enter.


4. To accept a suggestion, above the suggestion, click Accept Solution. To reject all suggestions,
close the tab.

Generating code suggestions from comments


You can describe something you want to do using natural language within a comment, and GitHub
Copilot will suggest the code to accomplish your goal.

1. In Visual Studio Code, create a new JavaScript (*.js) file.


2. In the JavaScript file, type the following comment. GitHub Copilot will suggest an implementation of
the function.

// find all images without alternate text

// and give them a red border

function process() {

Using a framework
You can also use GitHub Copilot to generate suggestions for APIs and frameworks. The following
example uses GitHub Copilot to create a simple Express server that returns the current time.

1. In Visual Studio Code, create a new JavaScript (*.js) file.


2. In the JavaScript file, type the following comment and then press Enter. GitHub Copilot will
suggest an implementation of the Express app.

// Express server on port 3000

3. To accept each line, press Tab, then Enter.


4. Type the following comment and then press Enter. GitHub Copilot will suggest an implementation
for the default handler.

// Return the current time

5. To accept each line, press Tab.

Enabling or disabling GitHub Copilot


You can enable or disable GitHub Copilot from within Visual Studio Code. The GitHub Copilot status icon
in the bottom panel of the Visual Studio Code window indicates whether GitHub Copilot is enabled or
disabled. When enabled, the background color of the icon will match the color of the status bar. When
disabled, the background color of the icon will contrast with the color of the status bar.

4/5
1. To enable or disable GitHub Copilot, click the status icon in the bottom panel of the Visual Studio
Code window.

2. If you are disabling GitHub Copilot, you will be asked whether you want to disable suggestions
globally, or for the language of the file you are currently editing.

To disable suggestions from GitHub Copilot globally, click Disable Globally.


To disable suggestions from GitHub Copilot for the specified language, click Disable for
LANGUAGE.

Further reading
GitHub Copilot

5/5

You might also like