# What is GitHub Copilot?

Date: 2021-06-30 · Author: Robert Scales · https://guidetoartificialintelligence.com/en/learn/what-is-github-copilot/

**Answer:** GitHub Copilot is an AI pair programmer that GitHub launched as a limited technical preview on June 29, 2021. It runs inside Visual Studio Code and suggests whole lines or entire functions based on the code and comments in the file you are editing.

Yesterday GitHub announced GitHub Copilot, a tool it calls an "AI pair programmer." Pair programming is a practice where two developers share one keyboard: one types, the other watches, suggests and catches mistakes. Copilot plays the second role. As you type in your editor, it proposes the next line, or sometimes a whole function, and you decide whether to keep it.

The model behind it is a new system from OpenAI, built together with GitHub. GitHub says it is much stronger at writing code than GPT-3, partly because its training data contains far more public source code, including code from public repositories on GitHub. For now Copilot is a technical preview with a limited number of places, so most developers will need to sign up and wait.

## How Copilot works

Copilot is installed as an extension for Visual Studio Code, a popular free code editor. It also works in GitHub Codespaces, the cloud version of that editor. While you work, the extension passes what you have written, code and comments alike, to GitHub's Copilot service, which returns suggestions right in the editor. Press Tab to accept one, keep typing to ignore it, or cycle through alternatives.

The context it uses is the file you have open. According to GitHub's FAQ, it does not yet read other files in your project, and very long files are trimmed so that only the few hundred lines before your cursor count. That means good comments, clear function names and helpful docstrings (short descriptions at the top of a function) give it more to work with.

GitHub lists Python, JavaScript, TypeScript, Ruby and Go as the languages where the preview performs best, though it understands dozens of others.

## A worked example

Copilot's product page shows a simple workflow: describe what you want in a comment, start the function, and let it fill in the body. In Python it might look like this:

```prompt
# Return the number of whole days between two dates given as "YYYY-MM-DD" strings
def days_between(start, end):
```

From that comment and signature, Copilot would propose a body, probably parsing both strings into dates and subtracting them. Your job is then to read it, ask whether it handles the cases you care about (what if `end` comes before `start`?), and test it.

GitHub's page also points to other uses: filling in repetitive code once you have written a couple of examples, suggesting unit tests that match a function, and showing several different solutions so you can compare approaches.

## What GitHub says about its limits

GitHub's FAQ is unusually direct about weaknesses:

| Claim to check | What GitHub says |
|---|---|
| How often is it right? | In an internal test on Python functions with their bodies removed, 43% correct on the first try and 57% within 10 tries |
| Does it test its code? | No. Suggestions may not compile or run |
| Can it be out of date? | Yes. It may suggest old or deprecated ways to use libraries |
| Does it copy training code? | About 0.1% of suggestions may contain snippets copied word for word |
| Is it secure? | Public code has insecure patterns, and Copilot can reproduce them |

GitHub's advice is to review and test Copilot's code like any other code. It also states that the code you write with Copilot's help belongs to you, and so does the responsibility for it.

> **Try it:** If you get access, write one comment describing a small function you have written before, let Copilot suggest a body, and compare it line by line with your own version. Then write three test cases and see whether its version passes.

## Will AI pair programmers replace developers?

Nothing in this preview points that way. Copilot is designed around a person who stays in charge: it suggests, and you accept, edit or reject. GitHub's own numbers show it misses more than half the time on a first try in its benchmark, and it cannot check whether its code runs. Someone still has to understand the problem, choose an approach, review every line and test the result. Those are the core of a developer's job.

What may change is how that time is spent. Much programming involves looking up how a library works or writing boilerplate, the repetitive scaffolding code that every project needs. If Copilot handles more of that, developers can spend more attention on design, review and testing. Early testers quoted by GitHub describe it as help with unfamiliar languages and frameworks, which suggests it may be most useful when you are learning something new.

There are open questions too: how code from public repositories should be used for training, how to spot the rare copied snippet, and how to keep insecure patterns out of suggestions. GitHub says it wants to discuss these with developers. For now, the healthy way to think about Copilot is as a fast, sometimes wrong assistant. Many expect tools like it to become common in editors, which makes code-reading and testing skills more valuable, not less.

## Sources

- Introducing GitHub Copilot: your AI pair programmer: https://github.blog/news-insights/product-news/introducing-github-copilot-ai-pair-programmer/
- GitHub Copilot: Your AI pair programmer (product page and FAQ, June 2021): https://copilot.github.com/
