Skip to main content

Getting started with GitHub Copilot in Visual Studio

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

GitHub Copilot can be managed through personal accounts with GitHub Copilot for Individuals or through organization or enterprise accounts with GitHub Copilot for Business.

GitHub Copilot is free to use for verified students, teachers, and maintainers of popular open source projects. For more information, see "About billing for GitHub Copilot."

Try GitHub Copilot

About GitHub Copilot and Visual Studio

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

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

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, you must have Visual Studio 2022 17.4.4 or later installed. For more information, see the Visual Studio IDE documentation.

Note: GitHub Copilot is not currently available for use with Visual Studio for Mac.

Installing the Visual Studio extension

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

  1. In the Visual Studio toolbar, click Extensions, then click Manage Extensions. Screenshot of the Visual Studio toolbar

  2. In the "Manage Extensions" window, click Visual Studio Marketplace, search for the GitHub Copilot extension, then click Download. Screenshot of GitHub Copilot extension for Visual Studio with the download button emphasized

  3. Close the "Manage Extensions" window, then exit and relaunch Visual Studio.

  4. Optionally, to check that GitHub Copilot is installed and enabled, go back to Manage Extensions, click Installed to view your currently installed extensions, then click GitHub Copilot to see status information. Screenshot of installed extensions in Visual Studio with GitHub Copilot emphasized

  5. Open or create a new project in Visual Studio.

  6. In the "Microsoft Visual Studio" dialog box, to copy your device activation code, click OK.

  7. A device activation window will open in your browser. Paste the device code, then click Continue.

    • To paste the code in Windows or Linux, press Ctrl+v.
    • To paste the code in macOS, press command+v.
  8. GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, click Authorize GitHub Copilot Plugin.

  9. After you approve the permissions, Visual Studio will show a confirmation.

Seeing 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 "Configuring GitHub Copilot settings on GitHub.com."

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++. The following samples are in C#, but other languages will work similarly.
  1. In Visual Studio, create a new C# (*.cs) file.

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

    C#
    int CalculateDaysBetweenDates(
  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, create a new C# (*.cs) file.

  2. In the C# file, type the following function signature. GitHub Copilot will show you a suggestion.

    C#
    int CalculateDaysBetweenDates(
  3. If alternative suggestions are available, you can see these alternatives by pressing Alt+] (or Alt+[).

  4. Optionally, 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.

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, create a new C# (*.cs) file.

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

    C#
    using System.Xml.Linq;
    
    var doc = XDocument.Load("index.xhml");
    
    // find all images
  3. To accept the suggestion, press Tab.

Enabling or disabling GitHub Copilot

The GitHub Copilot status icon in the bottom panel of the Visual Studio 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, it will have a diagonal line through it.

  1. To enable or disable GitHub Copilot, click the GitHub Copilot icon in the bottom panel of the Visual Studio window.

    Screenshot of editor margin in Visual Studio with the GitHub Copilot icon emphasized

  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 Enable Globally.
    • To disable suggestions from GitHub Copilot for the specified language, click Enable for LANGUAGE.

Further reading