AI Mitts logo

Github Copilot


GitHub Copilot is an AI-powered tool developed by GitHub, in collaboration with OpenAI. Its main purpose is to provide contextual code suggestions to developers based on the comments and code they write. It's like having an AI pair programmer that helps you code more efficiently by suggesting whole lines or entire functions of code.

The AI model behind GitHub Copilot, known as OpenAI Codex, is a generative pre-trained language model. This model has been trained on a diverse range of public internet text, which allows it to understand the context and generate useful code suggestions.

GitHub Copilot is available as an extension in widely used Integrated Development Environments (IDEs) such as Visual Studio, Visual Studio Code, Neovim, and JetBrains IDEs like IntelliJ, PyCharm and WebStorm.

Note: GitHub Copilot cannot write code independently. It only suggests code based on the context provided by the developer.  

Setting Up GitHub Copilot

The first step to using GitHub Copilot is setting it up for your personal or organization account. Here's a step-by-step guide on how to do it:

  1. Click on your profile photo located in the upper-right corner of any GitHub page, then select Settings.
  2. From the sidebar, go to the "Code, planning, and automation" section and click GitHub Copilot.
  3. On the GitHub Copilot settings page, click Enable GitHub Copilot.
  4. Choose your preferred payment option (monthly or yearly) and click Continue to get access to Copilot.
  5. Follow the instructions to confirm your payment details, then click Submit.
  6. Select your preferences, then click Save and get started.

You can also set up GitHub Copilot for your organization account by following similar steps. For detailed instructions, visit the GitHub Copilot for Business sign up page.

Installing GitHub Copilot

After setting up GitHub Copilot, you need to install the Visual Studio Code extension. Follow these steps:

  1. Visit the GitHub Copilot extension page in the Visual Studio Code Marketplace and click Install.
  2. A popup will appear, prompting you 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 prompted, sign in to your GitHub account in Visual Studio Code.
  5. When GitHub requests the necessary permissions for GitHub Copilot, click Authorize Visual Studio Code.

Using GitHub Copilot

Once you have installed the GitHub Copilot extension, you can start using it to get code suggestions. Here's an example of how you can get your first suggestion:

  1. Open Visual Studio Code.
  2. Create a new JavaScript (*.js) file.
  3. In the JavaScript file, type the following function header:
function calculateDaysBetweenDates(begin, end) { 

GitHub Copilot will automatically suggest an entire function body in grayed text. To accept the suggestion, simply press Tab.

Optimising GitHub Copilot Suggestions

While GitHub Copilot provides code suggestions, it's important to note that the quality of these suggestions depends on the context you provide. This context comes in the form of comments, code examples, and clear instructions – a practice known as prompt engineering. Here are some best practices for prompt engineering with GitHub Copilot:

Provide Clear and Detailed Instructions

Just like instructing a robot to make a sandwich, GitHub Copilot needs clear, step-by-step instructions to generate the code that best helps you. Start with a high-level context, followed by more detailed instructions in the form of comments and code.

Be Specific

The more specific you are with your instructions, the more accurate the code suggestions from GitHub Copilot will be. For example, if you want to retrieve data from an API, tell GitHub Copilot what type of data you want, how to process it, and what API endpoint to hit.

Provide Examples

In addition to telling GitHub Copilot what you want it to do, you can also show it what you want by providing examples. This helps GitHub Copilot understand the context and constraints of a particular code snippet better.

Iterate Your Prompts

If the initial prompt does not yield the desired response, delete the generated code suggestion, edit your comment with more details and examples, and try again.

Use Predictable Patterns

GitHub Copilot follows patterns in your code. So, using predictable patterns can help you get the results you want.

Use Consistent, Specific Naming Conventions

When declaring variables or functions, use names that are specific to their purpose. This will help GitHub Copilot understand the context better and generate more relevant suggestions.

Keep a Tab Opened of Relevant Files

Currently, GitHub Copilot does not have the ability to gain context from your entire codebase. However, it can read your current file and any files that are opened in your IDE. Keeping an open tab of relevant files can help GitHub Copilot provide more accurate suggestions.

GitHub Copilot and Public Code

GitHub Copilot uses a filter to detect and suppress suggestions that contain code matching public code on GitHub. If the filter is enabled, and the suggestion matches or nearly matches public code on GitHub, the suggestion will not be shown.

GitHub is also working on a feature that will provide a reference for suggestions that resemble public code on GitHub, allowing users to make an informed decision about whether and how to use that code.

Understanding GitHub Copilot's Limitations

GitHub Copilot has its limitations. For instance, if you have duplication detection enabled, you may receive limited suggestions or no suggestions when using the provided code examples. You might need to start by typing your own code to see suggestions from GitHub Copilot.

Also, while GitHub Copilot can provide suggestions for numerous languages and a variety of frameworks, it works best with Python, JavaScript, TypeScript, Ruby, Go, C#, and C++.

Beyond Your Editor: GitHub Copilot X

GitHub Copilot is not just limited to your IDE. With GitHub Copilot X, a suite of features that improve developer productivity outside of the IDE, you can translate, debug, test, document, and refactor code. Copilot X includes features like Copilot for Docs, Copilot for Pull Requests, Copilot Chat, Copilot for CLI, and Copilot Voice.

Now, you're equipped with all the knowledge you need to start using GitHub Copilot. Happy coding!

 Logo