Robert Johns | 03 Dec, 2023

How To Use GitHub Copilot in 2024 | Beginners Guide + Videos

In this article, we’ll cover how to use GitHub Copilot with the help of detailed video walkthroughs in VSCode.

Whether a beginner or a pro, we’ll show you how to use GitHub Copilot, including using natural language comments to generate code, autocompletions, test cases, and the chat tool.

And to help you get the most out of this article, we’ve included detailed videos showing you how to use GitHub Copilot for each use case.

Plus, if you’re new to AI coding assistants, we’ll start with an overview of what GitHub Copilot is, including what you can do with it, data privacy, and why you need to use it.

Sound good? Great, let’s dive in!

What Is GitHub Copilot?

So, what is GitHub Copilot anyway?

If you head to the GitHub website, you’ll see it described as an AI pair programmer built on top of the openAI codex.

That’s a fair answer. But let’s dig a little deeper! 

Released back in 2021, it’s actually the result of a collaboration between GitHub, OpenAI, and Microsoft.

This made it the first mainstream AI code assistant, which is probably why it’s currently the most popular AI coding assistant among developers.

Rather than a standard autocomplete tool like you get with any IDE, Copilot suggests entire blocks of code based on context.

What does that mean though?

Put simply, you can write some code or a comment that describes your goals, and Copilot will analyze it to offer code suggestions.

So whether you want to wrap your head around a new Python operator or you want help writing a tricky algorithm, Copilot can help you.

One of the most interesting things about Copilot is that it was trained on public GitHub repositories

If you read the docs, Copilot claims to be able to generate code for any language with a public repo on GitHub.

From my experience, it’s best suited to popular languages like Python, JavaScript, TypeScript, Ruby, Go, C#, and C++. 

For example, if you’re working on a Python project, you’re much more likely to get a helpful suggestion than you would if you were working in something like Fortran.

While we’re on the topic of training data, if you’ve spent any time perusing public repos on GitHub, you’ll know that they vary in quality and accuracy.

Because of that, you should probably assume that some of Copilot’s suggestions may contain outdated coding patterns, bugs, or references to defunct APIs.

GitHub’s own stats suggest that only 26% of Copilot's suggestions are accepted.

I think the message here is obvious. Always check any code suggestions before accepting!

In my opinion, this is exactly why these tools are no replacement for a real developer

But they can help you be more efficient.

Owing to its popularity, Copilot can integrate with various IDEs and code editors.

As of today, you can use plugins for Visual Studio Code, Visual Studio, JetBrains IDEs (IntelliJ IDEA, PyCharm) suite, Vim, Neovim, and Azure Data Studio.

I’ll use VSCode in this article, but it’s super easy to set up any of these.

To round things out, let’s talk about the newest Copilot feature, GitHub Copilot Chat.

This offers direct interaction with an LLM in the same format as you’d expect with ChatGPT or Google Bard.

Yep, that means you get your very own chatbot to help out when you’re coding.

As of today, this is in beta and only supported in Visual Studio Code and Visual Studio. We’ll be checking this out later in the article.

I should also mention that the next version, Copilot X, is scheduled to level up the chat tool even further, but there’s no word on when this will be released.

Do I Need To Worry About Data Privacy? 

This is something I wanted to figure out right away when getting started with Copilot. 

For example, is there any risk that my private code can be copied or used in Copilot’s suggestions to other coders?

The TL-DR here is that prompts and suggestions are retained for individuals unless you turn off code snippet collection in your settings.

You can also prevent data from prompts and suggestions being associated with your GitHub identity by contacting GitHub Support.

Most importantly, your code won't be shared with other Copilot users. I also like that data is encrypted in transit and at rest.

That said, if you’re hyper-security conscious, you need to know that GitHub and Microsoft personnel can access your data.

There’s also variance in data retention for individual and business users.

If you do spring for a Business plan, you don’t have to worry about this, as Copilot doesn’t retain any prompts or suggestions.

If you’re not sure which GitHub Copilot subscription is right for you, check out this quick comparison.

Copilot for Individuals

Copilot for Business

Price: $10/month or $100/year

Price: $19/user/month

Key Features: Telemetry, block suggestions that match public code, integrates with IDE or editor, multi-line function suggestions.

Advanced Features: All features of the individual, plus organization-wide policy management, audit logs, and HTTP proxy support with custom certificates. 

What Can I Do With GitHub Copilot?

Whether you’re new to development or a pro with years of experience, you can bet that AI tools like Copilot will be everywhere in the years to come.

That said, if you’re brand new to the world of AI coding assistants, you might be wondering what you can do with them.

Let’s take a look at some of the main use cases for GitHub Copilot:

  • Code Suggestions: Copilot can use your existing code’s context or natural language comments to suggest new code snippets or blocks.
  • Generate Test Cases: Copilot can help you generate comprehensive test cases for your existing code base. 
  • Code Refactoring & Optimization: Copilot can optimize code for better Big-O performance or to improve your code’s structure and maintainability.
  • Code Reviews & Bug Detection: Copilot can highlight issues or bugs in your code. No more searching for those tricky-to-find Python mistakes!
  • Documentation Assistance: Copilot can generate or update documentation.

Why Use GitHub Copilot?

Maybe you’ve read through the previous sections, but you’re still on the fence about why you should use Copilot?

I get it. After all, isn’t there a risk that AI will replace developers?

I think this is a common concern, but in my opinion, these tools are nowhere near ready to do the work of a real developer.

For now, I like to think of tools like Copilot or Amazon CodeWhisperer as AI-powered interns that can help me get things done a little faster.

This also means that I still need the coding knowledge and expertise to know whether Copilot’s suggestions are good or not.

Consider this scenario. You wouldn’t depend on an intern to handle a mission-critical project without supervision, so you should treat Copilot in the same way.

This also underlines an important point, which is that Copilot is not designed to replace learning

I think this is the trickiest aspect of introducing these AI tools into your workflow, as the temptation to rely on the AI to do your work can be massive.

But if you can find a natural balance, Copilot can help to make you a more efficient developer, whether you’re a student, beginner, or professional developer.

For example, if you’re a student, Copilot can help with:

  • Accelerated Learning via instant feedback and suggestions.
  • Homework & Project Assistance when you get stuck with challenging assignments.
  • Concept Clarification for how code works.

Similarly, new developers who might be fresh off a Python course can get help with:

  • Code Quality via cleaner, more efficient, and maintainable code.
  • Productivity Boosts with faster help versus using Google or Stack Overflow.

And lastly, pro devs can see benefits like:

  • Speed and Efficiency via real-time suggestions to help you code faster.
  • Code Reviews to quickly highlight potential issues and bugs.
  • Reduced Boilerplate for repetitive tasks by asking the AI to handle it.

How To Use GitHub Copilot

When it comes to AI tools like GitHub Copilot, one of the best ways to figure out how they work is to fire them up and learn by doing.

This can be a fast and fun way to take it for a test drive, but it might not be the most productive.

So, rather than hacking around, let’s take a structured approach and figure out how to use GitHub Copilot in the following ways:

  • Using natural language comments to describe our coding goals
  • Relying on Copilot’s autocompletions from existing codebase
  • Using Copilot to generate test cases for our existing codebase
  • Using the beta Chat feature to ask for help, seek advice, and generate code 

I think these are some of the most common aspects of using Copilot that any beginner should get to grips with.

So, without further ado, let’s get coding!

Important note: Make sure you have a GitHub account and an active Copilot subscription, then install the GitHub Copilot extension in your IDE or code editor and enable GitHub Copilot.

Using Comments To Generate Code

One of the coolest features of Copilot is the ability to generate lines of code from a natural language comment in your coding language of choice.

This is closely linked to prompt engineering, which has become popular thanks to AI tools like ChatGPT.

But what does this mean? 

Think about it like this: if I have an idea of what I want to do, I can write it out in plain English as a standard coding comment.

Copilot can then read this, interpret the information, and use it to generate code suggestions for me. I can then press tab to accept, or I can ignore it.

Of course, the more detailed I can be, the better the results.

Naturally, I may not be 100% satisfied with Copilot’s first suggestion, but that’s okay, as I can modify my comment or provide extra details

Copilot will then adapt to this and adjust its code suggestions.

I think the greatest benefit to this approach is that I can now use comments to speed up code generation. 

Oftentimes, this will just be to get the ball rolling on a project or a new idea, and I can then flesh it out in more detail myself.

Again, think of Copilot as your own AI intern who’s eager to help but perhaps not experienced enough to do the heavy lifting.

Now, as always, it’s super important to remember that while Copilot wants to help, it's essential to approach any suggestions with a critical mindset

Always review and test the suggested code for accuracy, efficiency, and security. 

And definitely don’t rely solely on auto-generated code without understanding its workings, as this can lead to issues down the road.

Think about this - how can you debug something if you don’t know how it works?!

Now, if you’re ready, check out the video below to see how you can use comments to generate code in Copilot.

I’ll be using Python, and I’ll be asking Copilot to help me generate various versions of a function to return the Fibonacci sequence, along with an object-oriented class.


Using Copilot’s Autocompletions

Perhaps the flagship feature of GitHub Copilot is its AI-generated autocompletions.

This is very different from the autocomplete you’ve experienced in your IDE, as it’s the result of analyzing a vast quantity of coding patterns to offer real-time suggestions

If you haven’t used Copilot before, you’ll probably be blown away by how this works.

Simply start writing code, and Copilot will jump in with an inline suggestion for what should come next.

Whether you’re writing a simple loop, a list comprehension, a function, a Class, or anything else you can think of, Copilot suggests code.

And honestly, it sometimes feels like magic or like it’s reading your mind!

Of course, the effectiveness of these autocompletions depends entirely on your coding style.

For example, if you write easy-to-follow code with solid naming conventions, Copilot will shine.

For example, if you're writing a function to filter a list, Copilot might suggest the whole function logic after you've typed just the first few characters.

Also, the more you use Copilot within your coding process, the better it gets at suggesting autocompletions that align with your coding style and project needs.

On the other hand, if you’re hacking away and using single-letter variable names and nonsensical function names, Copilot will struggle to understand your goals.

In the latter case, I actually think it’s better to avoid using Copilot, as it can be more of a hindrance than a help.

But of course, your opinion may differ from mine! 

The main takeaway is that Copilot can assess the context of your codebase to suggest code.

And these suggestions can be quite impressive!

That said, if the suggestions do not match your goals, simply reject them and carry on. Or, if you want Copilot to help, try using a comment (like we covered above) to give more context.

Remember, your AI-powered intern is doing its best to help you out, but it will always be taking your direction on how to give that help.

So if you’re not getting great suggestions, maybe consider whether your code is clear, or your naming conventions could be improved.

Equally, if you’re using a less common language, you’ll also find that Copilot may struggle to offer as much help as it would with something like Python.

And lastly, as always, review and test any suggested code for accuracy. 

Just like we mentioned with using comments, don’t rely on auto-generated code without understanding how it works!

Let’s now dive into a video to see how you can take advantage of Copilot’s autocompletions.

Once again, I’ll be using Python, but this time, I’ll be working with Copilot to create functions that encrypt and decrypt text, along with another function to check if a string is a palindrome.


Using Copilot To Generate Tests

When it comes to software development, testing is one of the most important aspects of the development lifecycle.

After all, we need our code to work as intended!

This is where tests come into play, and Copilot can help us again.

By building on the skills we’ve already covered with comments and autocompletions, we can ask Copilot to generate test cases for our code.

Like most things you can do with Copilot, there are multiple ways to tackle this.

To start with, we can provide contextual information in comments. 

Copilot can use this to analyze the logic and purpose of our functions or methods before generating relevant test cases. 

You can also ask Copilot to work with testing frameworks, like Pytest for Python, Jest for JavaScript, or JUnit for Java.

Depending on how deep you want to go, you can interact with Copilot to ask for help in detecting edge cases, refactoring existing test functions, or boosting code coverage.

If you’re ready to start, let’s jump into a video to see how you can use Copilot to help with testing.

In this example, I’ll be using Python, and I’ll be asking for help with creating test functions for all of the code we’ve generated so far in the previous sections.


Using Copilot Chat For Help & Advice

One of the newest features of Copilot is the integrated chat tool. This is currently in beta and only available in VSCode or Visual Studio.

This is a super handy feature, as it offers direct interaction with an LLM in the same format as you’re probably used to with ChatGPT.

Given their partnership with OpenAI, I'd be curious to see if there are any plans to integrate your Own GPT in the future, as this could be a cool way to personalize your CoPilot chat experience.

So, with the chat feature, rather than leaving your IDE and heading over to the ChatGPT interface, you can interact with a large language model inside your favorite Python IDE!

This is perhaps my favorite aspect, as it helps you stay in the coding flow.

You can choose to use the dedicated chat window or use a keyboard shortcut to show a pop-up chat box within your coding window.

The possibilities with this feature are almost limitless. 

For example, rather than skimming through traditional documentation or forums, you can ask questions and receive instant, context-aware answers. 

This also makes the chat tool ideal for learning about a programming concept or algorithm.

Just ask a question, and Copilot chat can provide explanations and code examples to enhance understanding.

I also like that the chat suggests other questions that you might want to ask to expand your understanding of the current topic.

A great example is when asking about an algorithm. Quite often, Copilot chat will then suggest learning about the time complexity.

This is great if you’re new to coding, as it can help you naturally expand your knowledge.

I will say that the lines do become a little blurred when it comes to sharing your code snippets with the chat tool to get help.

Technically, you can do the same thing by using natural language comments in your coding window.

But if you prefer the interactive and conversational approach of something like ChatGPT, the chat tool offers this.

So, feel free to have a conversation with Copilot about your code, whether that’s to get insights, optimizations, or corrections.

Let’s jump into a video to see how you can use the Copilot chat tool. Note that I’ll be using VSCode to ensure compatibility with the chat beta.


Tips & Advice on How To Use GitHub Copilot

If you’ve made it this far, you should have a solid understanding of how to use Copilot.

But maybe you want some tips and advice on how to use GitHub Copilot?

No problem, I have you covered! Here are my top tips for getting the most out of Copilot.:

  • Have Clear Intentions: Use descriptive, clear, and concise comments to convey your intentions to help Copilot translate comments into useful code suggestions.
  • Be Interactive: If an initial code suggestion doesn't fit, modify your input or provide more context to help Copilot adapt its suggestions over time.
  • Don't Rely on Autocompletions: Always review autocompletions! Please! You need to make sure they align with your requirements while maintaining your code's quality.
  • Use Chat for Deeper Insights: If you're facing a challenge or are unsure about implementing a functionality, use Copilot Chat for help.
  • Test Generated Code: Always test the code that Copilot suggests, especially if it's a critical part of your application.
  • Diversify Learning Sources: Copilot is excellent for quick solutions and code generation, but you also need to diversify your learning by using resources like documentation, tutorials, and forums.
  • Understand Licensing Implications: Remember that code generated by Copilot might be based on public repos. If your project has licensing requirements, review the generated code to avoid licensing conflicts.
  • Provide Feedback: Copilot not only learns and improves from code, but it also uses user feedback. If you encounter inaccuracies or have suggestions for improvement, share them. This can also help enhance the tool for the community.

Wrapping Up

We’ve now explored how to use GitHub Copilot! 

Whether you’re a beginner or a seasoned pro, we’ve covered how to use natural language comments, autocompletions, generating test cases, and using the GitHub Copilot chat tool.

We also included a range of detailed videos using Python and VScode to show you how to use GitHub Copilot for each of these use cases.

If you were brand new to the world of AI coding assistants, we even took a detour to summarize GitHub Copilot, including what you can do with it, data privacy, and why you need to use it.

Whichever language you want to code in, we hope you’ve found this article helpful and you now feel ready to integrate GitHub Copilot into your workflow.

Happy coding!

Are you new to development and ready to use an AI coding assistant as your personal tutor? Check out:

Dr. Anglea Yu's 100 Days of Code: The Complete Python Bootcamp for 2024

Frequently Asked Questions

1. What Is GitHub Copilot And How Do You Use It?

GitHub Copilot is an AI coding assistant that can generate code based on the context of your existing codebase or a detailed natural language comment. You use it within your preferred IDE or code editor by installing the required plugin or extension.

2. How Do I Ask GitHub Copilot To Write Code?

Copilot will automatically provide code suggestions as an autocompletion to match the context of your existing codebase, or you can produce a natural language comment to ask it to write code. You can also use the beta chat tool to generate and insert code into your codebase.  

People Are Also Reading:

By Robert Johns

Technical Editor for | 15+ Years in Python, Java, SQL, C++, C#, JavaScript, Ruby, PHP, .NET, MATLAB, HTML & CSS, and more... 10+ Years in Networking, Cloud, APIs, Linux | 5+ Years in Data Science | 2x PhDs in Structural & Blast Engineering

View all post by the author

Subscribe to our Newsletter for Articles, News, & Jobs.

I accept the Terms and Conditions.

Disclosure: is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

In this article

Learn More

Please login to leave comments