Get started with GitHub Copilot in Visual Studio Code (2023)

GitHub Copilot is an AI pair programming tool. It's a fancy way of calling it a "second developer" working in the source code editor. Copilot gives you auto-completion style suggestions as you code to help you code faster and more efficiently.

This article walks you through the steps to install and set up GitHub Copilot in Visual Studio Code. Next, you'll learn how to use Copilot to speed up the coding process.


To use GitHub Copilot, you must have a GitHub account. If you haven't already, you can do so atOfficial site.

Before doing this, make sure you are signed in to your GitHub accountSign up for GitHub Copilot.The service comes with a 30-day free trial, after which you must subscribe to one of the paid plans.

Get started with GitHub Copilot in Visual Studio Code (1)Get started with GitHub Copilot in Visual Studio Code (2)Get started with GitHub Copilot in Visual Studio Code (3)

If you don't plan to subscribe to a paid plan, be sure to cancel GitHub Copilot before the trial period ends to avoid being charged.

Finally, Visual Studio Code must be installed on the local machine. Install Visual Studio Code, go to officialVS code - download page.

Install the GitHub Copilot extension

Start by launching the Visual Studio Code editor. then clickexpandTo mark. Search using the search boxCopilot GitHub.Install and activate the extension (over 5 million downloads at the time of writing):

Get started with GitHub Copilot in Visual Studio Code (4)Get started with GitHub Copilot in Visual Studio Code (5)Get started with GitHub Copilot in Visual Studio Code (6)

Once the extension is fully up and running, you will be prompted to login to GitHub. Press the login button. The authentication process is quick because you are already signed in to GitHub and GitHub Copilot. If the process was successful, you will find the Copilot icon in the lower right corner of the VS code.

Ask Copilot a technical question

Although Copilot is billed as a coding assistant, you can ask it technical questions directly. It's perfect if you're studying for a technical interview and want quick answers to common interview questions.

To ask GitHub Copilot a question, prefix it: ask:

// Q: What is a class in object-oriented programming?

When you see Copilot's suggestion (greyed out), clickTo markPress a key on your keyboard to accept it as an answer. It precedes the answer:AThe Tab key works on both Windows and Mac computers.

You can also post any of these answers separately to get more information about them. Copilot predicts what you will ask and automatically completes the questions for you.

Use Copilot with HTML and CSS

Let's now turn our attention to coding, starting with the HTML example. Copilot can speed up the HTML writing process. Let's see how.

Create two HTML files in your project. These files must have a nameexample1.htmlexistexample2.html.Then open itexample1.htmlThe best in VS Code.

start typing Declaration of type of document. when you clickA nurseOn your keyboard, Copilot already knowsThe label becomes the next obvious one to add. So it suggests tags (clickTo markaccept).

Of these, Copilot recommends you use, closing, sure enough,represented by a

tags and paragraphs.

To generate an element, simply describe the element you want to generate in the comment and pressTo markHere's an example:


This will generate a

Element with blue text:


style="blue">this is a blue cup

You can also request a bulleted list using the following query:


Here are the results:

  • first time
  • 3
  • Article 2
  • 4
  • Article 3
  • 5

    As a best practice, styles should always be in a separate stylesheet. to makestyles.cssfile in the same folder as the HTML file.

    The following prompt generates a link element that points to the style sheet. write a query inTags in HTML:


    This will be the output:

     Relative ="list styles" type="Text/CSS" href="style.css">

    If the stylesheet files are in a different directory, just describe the directory structure in the query and Copilot will look inReference.

    Kopilot for Bootstrap

    With a simple "Add Bootstrap" query, Copilot generates a link to Bootstrap on the CDN. This is better than searching the internet for the latest Bootstrap link.

    Copilot also applies Bootstrap classes to your elements. when you start a

    element and press the spacebar, Copilot will know you most likely havealarmexistalert successfulclass, so it represents them.

    class="Alert alert successful">
     success!This warning box represents success or positive action

    just pressTo markAccept the suggestion.

    Copilot simplifies regular expressions

    If you've ever worked with regular expressions, you probably know how confusing interpreting patterns can be. But with Copilot by your side, writing regular expressions is a lot easier, because you can let Copilot write certain patterns for you.

    For example, to write a regular expression that matches phone numbers, put the following character in your JavaScript file:

    // regular expression to match phone numbers in the format (xxx) xxx-xxxx

    if you guessA nurseFrom your keyboard, Copilot will give you the required regular expression:

    it was telephone regular expression = /^\(\d{3}\) \d{3}-\d{4}$/;

    Regex is often used for testing, which is what the next section covers.

    Unit testing is easy with Copilot

    Copilot makes unit testing very easy. Let's look at an example.

    The following function takes a string, checks if it matches a regular expression, and parses the first and last values, then concatenates the numbers based on the operator:

    Function calculator(strait) {
     it was regular expression = /^\(\d{3}\) \d{3}-\d{4}$/;
     it was protocol = strait.protocol(regular expression)
     it was number 1 = dissectedInt(protocol[1])
     it was number 2 = dissectedInt(protocol[3])
     to change (protocol[2]) {
     case +: 
     yield number 1 + number 2;
     case -: 
     yield number 1 - number 2;
     case *: 
     yield number 1 * number 2;
     case /: 
     yield number 1 / number 2;
     yield invalid operator;

    Now you can tell Copilot to test the feature console log()Use a tip like this:

    // testing the calculator function

    Copilot records each operation and returns output:

    comfort.log(1+1) // 2
    comfort.log(1-1) // 0
    comfort.log(1*1) // 1
    comfort.log(1/1) // 1

    Copilot generates unit code for functionality testing when prompted:

    // Create a unit test for the calculator function
    it was claim = Require(to charge)
    claim.But(calculator(1+1), 2, The calculator can add)

    Not only does it generate code, but it also suggests operations other than adding to the test.

    Copilot chooses between several solutions

    So far we have seen how Copilot gives us advice. But always remember that you don't always have to choose the first suggestion. If you don't like the first solution, you can always choose the second one.

    Consider the following tips:

    // Create a function that takes an array and reverses it

    Start with the proposal review tabs. If you are not satisfied with the first one, hover over the text and move on to the next solution (using>icon). Once you find an acceptable solution, you can click onacceptbutton.

    Get started with GitHub Copilot in Visual Studio Code (7)Get started with GitHub Copilot in Visual Studio Code (8)Get started with GitHub Copilot in Visual Studio Code (9)

    Ask the co-pilot with more conditions

    You can specify multiple conditions when writing a Copilot query. This is useful if you want to write complex programs with multiple rules.

    Let's say you want to analyze a list of benefits under certain conditions. In function, you ask Copilot to do three things in your query (indicated by comments):

    Function Analysis fee(expense) {
     /* Parse the list of fees and return a string
    Triple (date, value, currency). Lines starting with // are ignored.
    Use Date() to parse dates

    Here we specified three conditions: parse list, ignore comments, and parse date. to wincontrol inputand choose the best solution among the proposals.

    One of my suggestions when testing is the following:

     yield expense.share(\N)
     .blankets(Wire => Wire.per. . beginning(//))
     .card(Wire => Wire.share(,))
     .card(([measure, value, currency]) => [novi measure(measure), number(value), currency]);

    That is OK. But beware - some of the suggestions I received have been usedred[0] == "/"Test which rules to ignore. This is not what we were looking for!

    It's important to carefully read the code generated by Copilot or any other AI tool to make sure it does what you expect.

    in conclusion

    In this tutorial, we learned the basics of using GitHub Copilot. Just write your advice in the comments and clickcontrol inputCheck out the suggestions.


    How do I set up GitHub Copilot in VS code? ›

    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.

    How do I enable GitHub Copilot in Visual Studio? ›

    Enabling or disabling inline suggestions

    You can choose to enable or disable inline suggestions for GitHub Copilot in Visual Studio Code. In the File menu, navigate to Preferences and click Settings. In the left-side panel of the settings tab, click Extensions and then select Copilot.

    What are the requirements to get GitHub Copilot? ›

    Before you can start using GitHub Copilot in your organization account, you will need to set up a subscription.
    • Go to the GitHub Copilot for Business sign up page.
    • Select an organization for which you want to purchase GitHub Copilot and click Continue.
    • Follow the steps to confirm your payment details, then click Save.

    Why is GitHub Copilot not working? ›

    This error indicates that you either do not have a GitHub Copilot subscription, or there was an error connecting to the GitHub API to request a token to use GitHub Copilot. To request another token from, try signing in and out of GitHub Copilot from your IDE.

    How do I enable Copilot code in Visual Studio? ›

    If you don't have Copilot through your organization, you can sign up here and start a free trial. From there: Open VS Code (even better, use Insiders). Open the Extensions view (Ctrl+Shift+X), search for GitHub Copilot and install the extension.

    Does GitHub Copilot train on my code? ›

    GitHub Copilot is a tool built into the code editor that is capable of writing code itself based on the code you've already written in your project. It uses OpenAI GPT-3, a language-prediction model, to generate human-like text and is trained on publicly available code from GitHub.

    How to get Git working in visual studio code? ›

    To initialize a new local repository, pick an existing or new folder on your computer and open it in VS Code. In the Source Control view, select the Initialize Repository button. This creates a new Git repository in the current folder, allowing you to start tracking code changes.

    How to setup GitHub on Visual Studio? ›

    Adding public GitHub accounts
    1. Select the icon with your initials in the upper-right corner of the Visual Studio environment. ...
    2. From the All Accounts submenu, select the plus sign to add an account, and select GitHub.
    3. You'll be redirected to the browser, where you can sign in with your GitHub credentials.
    Sep 30, 2022

    How do I enable Git in Visual Studio? ›

    To configure Git settings in Visual Studio, choose Settings from the top-level Git menu. Choose Git Global Settings or Git Repository Settings to view and configure global-level or repository-level settings. You can configure several common Git settings, as described in the following sections of this article.

    Does GitHub Copilot cost money now? ›

    Pricing for GitHub Copilot for Individuals

    The GitHub Copilot subscription is available on a monthly or yearly cycle. If you choose a monthly billing cycle, you will be billed $10 per calendar month. If you choose a yearly billing cycle, you will be billed $100 per year.

    How much is Copilot in Visual Studio? ›

    Summary Priced at $10 per month or $100 a year, GitHub Copilot is capable of suggesting the next line of code as developers type in an integrated development environment (IDE) like Visual Studio Code, Neovim, and JetBrains IDEs.

    What is the replacement for GitHub Copilot? ›

    Six interesting alternatives to GitHub copilot
    • Tabnine. Tabnine (formerly known as Codota) was among the first code completion tools to be introduced to the market. ...
    • CaptainStack. Developers and Stackoverflow are akin to human resource managers and Stackoverflow. ...
    • GPT-Code-Clippy (GPT-CC) ...
    • IntelliCode. ...
    • Asm-Dude.
    • Kite.
    Feb 6, 2023

    What is better than GitHub Copilot? ›

    CodeGeeX VS Code extension

    CodeGeeX also has a VS Code extension that, unlike Github Copilot, is free. The GitHub Copilot VS Code extension is technically free, but only to verified students, teachers, and maintainers of popular open source repositories on GitHub.

    Is GitHub Copilot illegal? ›

    In November of 2022, a class action lawsuit was launched against Microsoft, GitHub, and OpenAI. Submitted by Matthew Butterick and the law firm Joseph Saveri, the lawsuit claims that Copilot violates the rights of the developers whose open-source code the service is trained on.

    How to generate controller in Visual Studio Code? ›

    To add a controller, in Visual Studio Code right-click the Controllers folder and select New File. When the text box appears, enter CarsController. cs as the new file name. This will add a new C# file that will also open in the code editor.

    What is the difference between GitHub Copilot and Visual Studio IntelliSense? ›

    IntelliSense is known for its code-completion functionality, while also providing a variety of code editing features such as parameter info, quick info and member lists, while Copilot is an advanced AI system that goes much further, for example, generating whole code constructs or even entire programs in response to ...

    How many people have GitHub Copilot? ›

    Since its release, GitHub Copilot has transformed developer productivity for more than one million people, helping developers code up to 55% faster.

    What language is best for GitHub Copilot? ›

    While the product offers suggestions for several languages and a variety of frameworks, it does have its favorites. We suggest you use GitHub Copilot with JavaScript, TypeScript, Python, Ruby, Go, C#, and C++, as it works the most efficiently for these.

    Does GitHub Copilot write perfect code? ›

    A unique standout of GitHub Copilot compared to other solutions is its ability to understand natural language. This includes programming languages and human languages alike. It's worth noting that GitHub Copilot does not write perfect code.

    How powerful is GitHub Copilot? ›

    Today, GitHub Copilot is behind an average of 46% of a developers' code across all programming languages—and in Java, that number jumps to 61%. This work means that developers using GitHub Copilot are now coding faster than before thanks to more accurate and more responsive code suggestions.

    Why Git is not working in visual studio code? ›

    Enable Git in VS Code

    Go to File > Preferences. Go to Settings. Type Git: Enabled in the search bar. Make sure that the box is ticked.

    How to use Git command line in Visual Studio Code? ›

    You can create and checkout branches directly within VS Code through the Git: Create Branch and Git: Checkout to commands in the Command Palette (Ctrl+Shift+P). If you run Git: Checkout to, you will see a dropdown list containing all of the branches or tags in the current repository.

    How to connect Git to GitHub to Visual Studio? ›

    In Visual Studio, select Team Explorer from the View menu. In the Team Explorer pane, click the Manage Connections toolbar icon. Click the Connect link in the GitHub section. If none of these options are visible, click Manage Connections and then Connect to GitHub.

    How does GitHub work with Visual Studio code? ›

    Working with GitHub in VS Code
    1. If you are not redirected to VS Code, you can add your authorization token manually. ...
    2. From the GitHub repository dropdown you can filter and pick the repository you want to clone locally.
    3. Authenticating with an existing repository. ...
    4. Follow the steps to sign into GitHub and return to VS Code.

    What's the difference between Visual Studio and Visual Studio code? ›

    Visual Studio is an Integrated Development Environment, also known as an IDE. Visual Studio Code is a code editor. A developer can easily edit their code. VS is slower when it comes to performing across different platforms.

    How to install Git plugin in Visual Studio? ›

    Installing the GitHub Extension for Visual Studio
    1. Visit the GitHub for Visual Studio site.
    2. Click the Download GitHub Extension for Visual Studio button.
    3. In your computer's Downloads folder, double-click GitHub. VisualStudio. ...
    4. In the pop-up window, click Install.
    5. After the installation is completed, run Visual Studio.

    What is difference between Git and GitHub? ›

    While Git is a tool that's used to manage multiple versions of source code edits that are then transferred to files in a Git repository, GitHub serves as a location for uploading copies of a Git repository. In a sense, then, there's no comparison when it comes to Git vs. GitHub as far as their function.

    Can I use GitHub Copilot offline? ›

    It's local as any other one, you can use features like that but it works perfectly fine offline.

    Is GitHub Copilot included in Visual Studio subscription? ›

    A: Yes. Along with GitHub Enterprise, you receive all of the benefits of a standard Visual Studio subscription including software downloads, cloud services, technical support, and partner benefits as if the subscription was purchased separately.

    Is copilot free for Visual Studio? ›

    GitHub Copilot requires Visual Studio 2022 17.4.4 or newer. For older versions, use GitHub Copilot requires a subscription. It is free for verified students and maintainers of popular open source projects on GitHub.

    How long is copilot free? ›

    While it's free for verified students, teachers, and open source project maintainers, non-eligible users can enjoy a 60-day free trial. In this article, we'll show you how to get started with GitHub Copilot's free trial and explore the benefits of using this innovative tool. So, let's get started!

    What are the limitations of Copilot? ›

    One of the biggest disadvantages of using Copilot is that it can be distracting. Copilot can suggest many different things, which can be overwhelming for some developers. This can lead to a loss of concentration, which can ultimately slow down the coding process.

    Does Copilot collect my code? ›

    Depending on your preferred telemetry settings, GitHub Copilot may also collect and retain the following, collectively referred to as “code snippets”: source code that you are editing, related files and other files open in the same IDE or editor, URLs of repositories and files path.

    Is Copilot vs Code extension free? ›

    To get started, all you need is Visual Studio 2022 version 17.4. 4 or later, and a GitHub Copilot subscription. GitHub Copilot is free for verified students and for maintainers of popular open source projects on GitHub.

    Does Google have something similar to Copilot? ›

    Google rebrands AI tools for Docs and Gmail as Duet AI — its answer to Microsoft's Copilot.

    How do I activate Copilot in Microsoft 365? ›

    Right-click the Word key, select the New menu, and select the String Value option. Name the key Microsoft.Office.Word.CoPilotExperiment and press Enter. Double-click the newly created key and set its value to true to enable Copilot. Click the OK button.

    How do I set up Microsoft Copilot? ›

    In Visual Studio Code, open the Extensions view by clicking on the Extensions icon in the left-hand menu or by pressing Ctrl+Shift+X on Windows or Command+Shift+X on Mac. Search for "GitHub Copilot" in the Extensions view. Click on the "Install" button next to the "GitHub Copilot" extension.

    How do I enable GitHub Copilot for an organization? ›

    Next to the organization, click Settings. In the "Code planning, and automation" section of the sidebar, click Copilot, and then click Access. Under "User permissions," to enable GitHub Copilot for selected teams or users in your organization, select Purchase for selected teams/users and click Save.

    What is the difference between GitHub Copilot and tabnine? ›

    The primary differences between Tabnine and Copilot are their approach to code completion, language support, and IDE integration. Tabnine focuses on predicting code snippets using deep learning, while Copilot uses the OpenAI Codex model for context-aware suggestions.


    Top Articles
    Latest Posts
    Article information

    Author: Greg O'Connell

    Last Updated: 24/08/2023

    Views: 6369

    Rating: 4.1 / 5 (42 voted)

    Reviews: 89% of readers found this page helpful

    Author information

    Name: Greg O'Connell

    Birthday: 1992-01-10

    Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

    Phone: +2614651609714

    Job: Education Developer

    Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

    Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.