GitHub Copilot 101: Setting up and Getting Started
GitHub Copilot is YOUR personal coding assistant.
It’s YOUR pair programming companion — a very intelligent and obedient and helpful. The prospect of developers collaborating with this multifaceted and dynamic coding assistant appears both exciting and formidable. Welcoming this versatile and fully-equipped coding assistant is something we should eagerly anticipate.
In this collection of articles, I explore the characteristics of the tool, its setup, and illustrate its usage through various examples. We will go over setting up the tool for our IDEs, start with writing a sample Java program to building a microservice. We will also ask Copilot’s help in coding our tests as well as designing the tests and programs in Test Driven Development (TDD) style.
Introducing GitHub Copilot
GitHub Copilot is a revolutionary programming companion developed by GitHub and OpenAI. It is powered by OpenAI’s Codex model to help us code!
Integrated with the code editor, Copilot saves a bundle of time by suggesting whole lines or blocks of code as you type.
It is designed to understand our coding intentions and provide real-time suggestions as we write or edit the code. It seamlessly integrates into our development environment and learns from billions of lines of public code (trained on range of public code repositories, which means it understands dozens of programming languages) to help us with a broad range of tasks.
In fact, GitHub Copilot can suggest whole lines or blocks of code, making it a dynamic aid for developers ranging from beginners to seasoned professionals. It supports a multitude of languages and frameworks, making it a versatile tool in the arsenal of modern-day programming. Whether w are writing a new function, hunting down pesky bugs, or learning a new language, Copilot is there to assist us every step of the way.
Copilot utilises advanced machine learning algorithms to provide highly relevant suggestions. It’s like a pair programmer that learns from our coding style and gives you personalised suggestions. Whether you’re defining a new method, looking to iterate over an array, or searching for a way to structure your code, Copilot can help by providing suggestions that fit our needs.
The more we use GitHub Copilot, the more it learns about our style and the context of the code we are writing. It can save us bundle of time by reducing the amount of boilerplate that we may have to write, and it can help you discover new APIs or libraries by suggesting relevant code. It can also help write beautiful tests, including starting a greenfield development using TDD style if needed!
In addition to all these features, GitHub Copilot can also be an excellent learning tool, especially for new languages or frameworks. As we learn Java examples through this series, we’ll be using GitHub Copilot extensively, seeing in real-time how it can speed up our learning process and enhance the understanding of Java programming.
Remember, GitHub Copilot is a tool designed to help us, NOT REPLACE US! It’s here to make coding easier and more efficient, but the final decisions always remain in our hands.
Embrace the assistance it provides, but also remember to apply our judgment and creativity as a programmer. Let’s start setting up the tool in the following section.
Setting up Copilot
Before we can utilise the power of GitHub Copilot, we must first set it up in our coding environment. The following instructions guide you through the installation process of GitHub Copilot using Visual Studio Code (VS Code).
We stick to VS Code in this article, but you can try out other IDEs too as there are a handful of plugins that helps integration. For example, IntelliJ IDE has a IntelliJ GitHub Copilot plugin too.
- Install Visual Studio Code: (skip this step if you already have VS code). GitHub Copilot is an extension for Visual Studio Code. If you haven’t already installed VS Code, you can download it for the visual studio’s official site. Simply follow the installation instructions to get the VS code installed.
- Install GitHub Copilot: Once VS Code is installed, search for Copilot in the Extensions view. You’ll find the extension (as shown in the image below):
Click the Install button on the GitHub Copilot box.
- Connect with GitHub: After installation, you’ll need to connect GitHub Copilot to your GitHub account. You may see a notification popup at the lower right of your window, as shown below:
Click on the profile icon in the lower-left corner of VS Code, then click “Turn on Settings Sync…”. You’ll be prompted to sign in to your GitHub account. If you don’t have a GitHub account yet, visit https://github.com/ to create one.
Once you’ve followed these steps, GitHub Copilot should be ready to use in VS Code.
Getting Started with GitHub Copilot
With GitHub Copilot installed and set up, we can start coding. As we type, GitHub Copilot automatically suggests code to complete your line. When we see a suggestion, we can simply press `Tab` to accept it. If you want to see alternative suggestions, you can press `Ctrl+Enter` (or `Cmd+Enter` on macOS), and a dropdown will appear with other possible completions.
Remember, GitHub Copilot doesn’t just provide suggestions for single lines of code — it can generate whole functions or blocks of code. For instance, if we start typing a function that calculates the factorial of a number, Copilot will likely provide a suggestion to complete the function based on its understanding of your intent.
In the next article, we’ll continue exploring how to effectively use GitHub Copilot in writing Java programs.
If you are interested in learning Python using CoPilot — here’s a book that might help you: Learn Ai-Assisted Python Programming: With Github Copilot and Chatgpt
Stay tuned!