Today, iCONEXT will show you how to use the GitHub Copilot in action. If you don’t know what GitHub Copilot is, you can read our article GitHub Copilot, an AI tool for software developers.
I had the opportunity to use GitHub Copilot when Microsoft initially launched the service. However, at that time, it was still suggesting incorrect code and wasn’t very smart, so I didn’t pay much attention to it. After Microsoft added the GitHub Copilot Chat feature at the end of 2023, I tried using GitHub Copilot again in early 2024. Not only has it become significantly smarter, but it also greatly helps reduce coding time. However, since it’s not a free service, whenever I recommended it to someone, the conversation usually ended there.
Finally, the day has come when Microsoft announced that GitHub Copilot is now available for free with some limitations at the end of 2024. So, let’s try it out! In this article, I will walk you through some examples of using GitHub Copilot in Visual Studio.
Prerequisites
- Sign up for a GitHub account
- Install Visual Studio 2022
Account Settings
Once you’re ready, let’s get started!
1. Open Visual Studio and click on File > Account Settings

2. Click Add, then select GitHub.

3. You’ll be redirected to the browser, where you can sign in with your GitHub account. If you are already logged in, the screen will appear as shown below. Then, click Continue.

4. After signing up, you’ll see a success window, and you can close the web browser.

5. When you return to Visual Studio, your GitHub account will be displayed.

Getting started with GitHub Copilot
1. Code Completion
The better you write code, the better the suggestions from Copilot will be. Therefore, if you’re a junior developer, I would recommend that you focus on building a strong foundation in coding first. This is a very important thing that you should do.
You can learn from your regular learning resources, or have AI generate code based on your instructions and try to understand it. However, if you use AI only to generate complete code, you won’t improve your own skills.
If you have been coding for a long time without using AI, you’ll find that once you start using it, it can significantly reduce your coding time. This allows you to focus on other tasks, such as code review, revisiting code structure, and improving your skills in other areas.
Now, it’s time to get started. I’m going to create a function called GetRaidDetail, which retrieves values from the database and displays them on a webpage.

The result value is not yet a RaidDetailViewModel, so I need to map the object first. Normally, I would write the code to map the object myself. When I use Copilot, it knows what I am doing. So, when I press Enter, Copilot will predict what I need based on the function name and the result variable.

Normally, it takes about 2 minutes to check the properties in the result and RaidDetailViewModel and then start writing the code. With Copilot’s help, it only takes 3 seconds to predict and generate a sample code in grey—exactly what I need. Just press Tab to let Copilot insert the code, and it’s done. It’s so quick, isn’t it?
2. Fix with Copilot
When writing code, Visual Studio sometimes underlines parts of the code to indicate issues that I should fix. Normally, I read Visual Studio’s suggestions and find ways to improve the code. This time, I will improve the code with Copilot. Let’s take a look!

The code above retrieves data from the database, but there is a warning that the value might be null. Therefore, you should improve this code.

Hover the mouse over the light bulb icon and select Fix with Copilot. Wait for a moment while Copilot thinks, and then you’ll receive a suggestion like this.

If the code suggestion from Copilot is usable (which has worked over 95% of the time based on my experience), click the Accept button to let it fix the code.
3. Copilot Chat
It’s a new feature that’s very useful, and I’ve learned a lot from it. Since it works within Visual Studio, it helps with code much better than external AI, in terms of improving code, explaining code, and even fixing errors.
To open the Copilot Chat window, proceed with the following steps.
1. In Visual Studio, when you click on GitHub Copilot in the top left corner, it will display the ‘Open Chat Window’ option.

2. The Copilot chat window will appear as shown below.

3. If you can’t figure out what to do with Copilot or don’t know what it can do, try typing / to see the basic commands available. At the time of writing this article, there are six commands: doc, explain, fix, help, optimize, and tests.

Below are the commands that I tried.
explain: It is to have Copilot explain the functionality of the code we specify.
fix: It is to have Copilot fix the errors.
optimize: It is to have Copilot improve the code.
tests: It’s using Copilot to generate unit tests for the selected code.
If I type #, it will display the file names I’ve written.

The image shows the command to have Copilot explain the functionality of the code in the HomeService.cs file. The next image is an example of the result received from Copilot. It explains every function I’ve written in that file and provides a brief summary at the end.


The limitations of GitHub Copilot’s free version
Briefly, the free version of GitHub Copilot allows 2,000 code completions per month and 50 Copilot chats per month. The paid version has no limitations on these two features. For more details, you can check the Copilot Plans.
Now, it’s available for free, so don’t you want to give it a try? I expect it will keep getting smarter and make our work more convenient in the future. Additionally, there are many more features of GitHub Copilot that I don’t mention here.You can read more details of GitHub Copilot’s features.
Source: Dev Blogs