GitHub Copilot - Everything you need to know
Tags: github, ai, webdev, computerscience
Published: 2021-07-12 10:59:49

Let's talk about a very exciting product that was recently launched by GitHub, which is called **GitHub Copilot**.
GitHub Copilot is your new AI Pair programmer, powered by OpenAI. It helps you to write utilify functions, tests, and explore new API(s) without having to lookup for answers on internet. It generates or autocomplete code for you.


## Installation
![Copilot.github.com](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qc8kko0i4w31fd0ndud.png)

It's currently not available publicly, so if you want to use it, you've to join the waiting list by visiting [GitHub Copilot](https://copilot.github.com/) and head over to **[Sign up](https://github.com/features/copilot/signup)** page.

![Copilot waiting list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q79kks1p9oup9nldv84d.png)
It is already enabled on my account 🎉, so I can use it right now.
Once it is enabled, you can install it in [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot)

After installation and authenticating it with your GitHub, you'll see Copilot icon in Visual Studio Code at bottom right.
![Extension Icon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1qb4nmi2tl54feyufze.PNG)
You can enable/disable Copilot by tapping this icon.

## Usage
Let's start with some simple and basic utilify functions.

Suppose, I want to have a function which accepts a number as an argument and returns the double of it, here's how Copilot helps me.
![Double The Number Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/43g2027xg0ramnk0lztb.PNG)

Let's try with a function that finds even numbers in an array
![Even Number Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h42zjv17dijv9c585igs.PNG)

Maybe try something related to dates?
![Days in Year Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im0py4t76r3f5bj6nuci.PNG)

When Copilot gives you a suggestion and you hover the mouse on last character, it gives you options to navigate between _Next_ and _Previous_ , _Accept_ current suggestion or _Open Copilot_ which shows list of all the suggestions available.
![Open Copilot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gculinjsiagumsb96d1g.PNG)


These were some simple utility functions, maybe we should give a try to use Node.js default modules, such as `fs`.
Depending on the what function name you use, Copilot gives different suggestions.

![Read File Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dc3txaezd4jnswaavuyz.PNG)
![Read File and Print Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnbdhlze6vayqalldwvs.PNG)
![Write File Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/se3p3vo95rcrb1dw8bm5.PNG)

Okay, enough of simple examples, let's quickly build a simple CLI based application that fetch user GitHub details (`api.github.com/users...`)

CLI Applications start with a _shebang_ which syntax I always forget, but now no more (Yes, Copilot also works for comments
![Shebang Suggestion](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uekntqgc8hfa7pjvyc1h.PNG)

Here's the basic template
![CLI application template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rap9962zzpnilloz5x69.PNG)

Now let's start using copilot. The very first thing is to extract username from arguments as the user will be passing it dynamically
```js
./cli.js khattakdev
```
Here `khattakdev` is a GitHub Handle

Here's the code for extracting username from arguments
![Get Values Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgeaszux51b07shri8qh.PNG)

and here's the code for making an API call, since `axios` is imported, so copilot suggests an axios call
![Make an API Call](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rxl6wvobysijiop8mbf.PNG)

Here's the whole code for CLI application, which we created in a minute using copilot.
![CLI application Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clxfajf1vv19g5ibg6un.PNG)


## Conclusion
Copilot is an awesome tool that works for creating utility functions, writing test cases, and exploring new API(s). It also works for comments and it gives you multiple suggestions.