How to add GitHub Copilot in VS Code
Akshat Virmani

Akshat Virmani

6 min readAug 24 2024

How to add GitHub Copilot in VS Code

GitHub Copilot is a major advancement in AI-assisted software development. This tool uses machine learning to provide intelligent code suggestions, saving developers time on repetitive tasks and boosting productivity. In this guide, we'll walk through the steps for integrating GitHub Copilot into Visual Studio Code so you can see the benefits of this innovative technology for yourself.

We’ll cover what GitHub Copilot is, how it works, and how we can use it as your coding companion with Visual Studio Code.

What is GitHub Copilot?

GitHub Copilot, created by GitHub and OpenAI, is an AI-powered code completion tool and coding assistance that provides real-time AI-powered code suggestions for lines or blocks of code as developers type for numerous languages and can help infrastructure as code development.

Copilot can also help create database queries and suggest APIs and frameworks. It responds in natural language or code snippets. It has become one of the most popular VS Code extensions nowadays.

Why use GitHub Copilot?

Using GitHub Copilot has lots of advantages. Some of them are:

1. Integration with code editors:

GitHub Copilot integrates easily and smoothly with Code Editors Like Visual Studio Code. This integration ensures that developers can access Copilot’s features directly within their code editor, reducing the need for context switching and enhancing productivity.

2. Reduce errors:

By suggesting correct syntax and methods, errors can be minimized, which improves code quality. This real-time assistance ensures that common mistakes are avoided, resulting in cleaner and more reliable code. By catching errors early in the development process, Copilot improves code quality and reduces the time spent on debugging and fixing issues later.

3. Increase in productivity:

Copilot can speed up the coding process by suggesting lines of code and completing functions, which allows developers to focus on higher-level design and problem statements.

4. Wide language and framework support:

GitHub Copilot is trained in diverse programming languages and various frameworks, making it versatile for projects with different tech stacks. Whether you are working on web development, data science, machine learning, or mobile app development, Copilot provides relevant suggestions tailored to the specific language and framework in use.

5. Learning and discovery:

Developers can learn new coding patterns and discover alternative ways to solve problems by reviewing the suggestions provided by Copilot. This continuous learning process helps developers improve their skills and stay updated with the latest coding standards and methodologies.

6. Code suggestions:

Get inline code suggestions while iterating and writing code. Copilot offers real-time suggestions and completions that align with the current context as developers write code, making the coding process more efficient.

7. Consistent coding style:

GitHub Copilot promotes a consistent coding style by providing standardized code suggestions that align with best practices. By leveraging Copilot's suggestions, developers can ensure that their code remains clean, well-structured, and aligned with industry standards.

Using GitHub Copilot with Visual Studio Code

Now, let’s see how to install GitHub Copilot on VS Code and how to use it.

Prerequisites

A Code Editor Like Visual Studio Code GitHub Copilot

Installation & setup

To add GitHub Copilot to your Visual Studio Code, Follow the installation instructions below:

  1. Open the Visual Studio Code and go to Extensions on the left-side panel; this will lead you to the Visual Studio Marketplace
  2. Search For ‘GitHub Copilot’ or ‘Copilot’ in the search bar. Click on the blue install button.

  1. After the installation, click on the GitHub link below the GitHub Copilot Extension Overview. It will redirect you to the GitHub website.

  1. After Signing In to your GitHub Account, Click on your profile icon in the upper-right corner and select ‘Your Copilot’.

Remember,GitHub Copilot is not free. Users must buy a monthly or yearly active subscription, which costs $10 and $100, respectively, or they can access GitHub Copilot via the GitHub Student Developer Pack.

  1. After purchasing the subscription, click on the Copilot icon at the bottom of the Visual Studio Code to make sure the Copilot installation is done successfully,

A prompt will appear with Copilot Status. It should display ‘Status: Ready’.

Now that GitHub Copilot is Installed. Let’s explore it a little.

Using GitHub Copilot to generate code

To generate code for any language you want to work with, create a file or place it in the existing one. Write a comment with whatever you want to do. In this case, we will learn how to create a number array in JavaScript.

Create a file with .js extension. In this case, we have named the file test.js.

    //Create an array of numbers

And then press enter. It will show you some suggestions that can be selected using the Tab button. Repeat the Tab button process till your code is complete. It will look something like this.

    //Create an array of numbers
    var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

GitHub Copilot Chat

You can also use GitHub Copilot Chat to do the above. It is available on GitHub Mobile and supports Visual Studio Code and JetBrains IDE. It can be used for AI-driven chat conversations and can provide coding suggestions. Let’s take another example of this using natural language.

Press Ctrl + I on Windows or Cmd + I on Mac, or simply click the chat icon in VS Code for the inline chat. GitHub Copilot Chat will open. Type your desired problem or statement in the Chat input field or chat panel to improve your code and get suggestions with smart actions. The exact suggestions for the code may vary from system to system.

In the example shown down below, we will ask Copilot to create a mini calculator with a user interface. Here is the result:

GitHub CLI

GitHub Copilot CLI is generally available, and you can ask GitHub Coplit in CLI to give terminal suggestions or to explain commands you are unfamiliar with.

To download GitHub CLI for your system, visit their website and repository or watch their YouTube video for the installation.

Let’s take a quick example of how GitHub CLI works:

GitHub autocomplete

GitHub Copliot can also help you complete your code block so you don't have to write the full code, which can take effort and be time-consuming. It gives inline suggestions as we type directly in the editor.

Other features of GitHub Copilot

There are some other features of GitHub Copilot that are available for enterprises, administrators, and organizations to use in their projects, such as:

Pull Request Summary: AI-generated summaries of the changes made in a pull request, which files they impact, and what a reviewer should focus on when conducting their review. This feature streamlines the review process, saving time and ensuring that critical changes are not overlooked.

Copilot Knowledge Bases: Create and manage collections of documentation to use as context for chatting with Copilot. This allows users to specify a knowledge base as the context for their questions, enabling Copilot to provide more accurate and context-aware answers, making it an invaluable tool for large-scale projects with extensive documentation.

Conclusion

Finally, we have reached the end of this tutorial, where we learned how to use the GitHub Copilot Extension on Visual Studio Code and its key features. GitHub Copliot is a game changer in Software engineering. It can help users reduce errors, save time and effort, provide good code suggestions, and create innovative solutions. Whether you are an experienced software engineer or just starting out, integrating Copilot into your workflow can elevate your coding experience. With its assistance, we can focus more on creativity and problem-solving while letting the tool handle repetitive tasks.

Resources:


About the author

I am a DevRel and App Developer who loves creating content and building communities. I want to live a happy life, help others, and become a better Developer Advocate.

More articles

logo
Get insights and tips on technical Content creation

Augment your marketing and product team to publish original technical content written by subject-matter experts for developers.

+1 (302) 703 7275

hi@hackmamba.io

Copyright © 2024 Hackmamba. All rights reserved