- You will need VS 2022 17.1 or later: https://devblogs.microsoft.com/visualstudio/visual-studio-2022-17-1-is-now-available/
To use GitHub Copilot, you first need to install the Visual Studio extension.
-
Open Visual Studio.
-
In Extensions | Manage Extensions, from the Visual Studio Marketplace, install the GitHub Copilot extension for Visual Studio.
- Close the dialog, then exit and relaunch Visual studio.
- After restarting Visual Studio, use Extensions | Manage Extensions | Installed to confirm that the GitHub Copilot extension is installed and enabled.
Having problems installing? Visit the Feedback forum.
GitHub Copilot provides suggestions for dozens of languages and a wide variety of frameworks, but it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C#, and C++. The following samples are in C#, but other languages will work similarly.
-
Create a new C# Console App project by following the instructions in steps 1 and 2 here.
-
Name your project "Copilot Demo".
- Click "Next".
-
Click "Create".
- The very first run, you will be presented with a message to activate your connection to GitHub
- A device code will be copied automatically to the clipboard. Paste it on the GitHub device authorization page that will open. If you miss the device code, you will find it in the status bar, at the bottom left of Visual Studio, as well as on the GitHub Copilot output window pane.
- After successful authorization, proceed to read and approve the telemetry terms.
After installation, a GitHub Copilot icon should appear in the editor margin at the bottom of your Visual Studio window, in the lower left.
and your file should show short "Hello, World!" code.
-
Below that, type the following function header:
int CalculateDaysBetweenDates(
-
GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
-
Press
Tab
to accept the suggestion.
GitHub Copilot will attempt to match your code's context and style. You can edit the suggested code as you choose.
For any given input, GitHub Copilot can provide multiple suggestions. As the developer you are always in charge; you can select which suggestion to use, or reject them all.
-
Clear the file (or start a new one), and type the following again:
int CalculateDaysBetweenDates(
-
GitHub Copilot will again show you a suggested completion.
-
Instead of pressing
Tab
, pressAlt
+.
(orAlt
+,
).GitHub Copilot will cycle through other alternative suggestions.
-
When you see a suggestion you like, press
Tab
to accept it. -
If you don't like any of the suggestions, press
Esc
.
You can also hover over a suggestion to see the GitHub Copilot command palette for choosing suggestions.
GitHub Copilot can understand significantly more context than most code assistants, and can generate entire functions from something as simple as a comment.
-
Clear the file (or start a new one), and type the following:
using System.Xml.Linq; var doc = XDocument.Load("index.xhml"); // find all images
Press
Enter
. -
GitHub Copilot will automatically suggest an implementation. Press "tab" to accept it.
-
Enter a second comment
// and give them a red border
GitHub Copilot can do even more. Check out the examples on copilot.github.com to see more, or the Gallery in this repository for the latest examples from us and the community.
Got an example of your own? We welcome you to share it on our Feedback forum.
The following lists the most common keyboard shortcuts relevant for GitHub Copilot. If you wish to rebind them, check out the configuration guide.
-
Accept an inline suggestion:
Tab
. -
Dismiss an inline suggestion:
Esc
. -
Show next inline suggestion:
Alt + .
. -
Show previous inline suggestion:
Alt + ,
. -
Trigger inline suggestion:
Ctrl + Alt + \
.
The GitHub Copilot status icon in the bottom panel of the Visual Studio window indicates whether GitHub Copilot is enabled or disabled. It will have a diagonal line through it when disabled. To enable or disable GitHub Copilot, click the icon. You will be asked whether you wish to toggle for the current file, current file type, or globally.
To learn more about configuring GitHub Copilot, go to the documentation table of contents.