GitHub Copilot Tutorial

This article describes the GitHub Copilot tool and the main guidelines and assumptions regarding its use in software development projects. The guidelines concern both the tool’s configuration and its application in everyday work and assume the reader will use GitHub Copilot with IntelliJ IDEA (via a dedicated plugin).

GitHub Copilot: What Is It?

GitHub Copilot is an AI developer assistant that uses a generative AI model trained for all programming languages available in GitHub repositories. The full description and documentation of the tool is available here. 

There are other similar tools on the market, such as OpenAI Codex, JetBrains AI Assistant, or Tabnine, but GitHub Copilot stands out due to the following features:

Our Goals

Our main goal for using GitHub Copilot was to improve the efficiency of writing code and its quality. In addition, we intended it to support and assist us in work in which programmers lack knowledge and experience. Here are the specific goals that we wanted our development team to achieve by using GitHub Copilot:

1. Accelerating Development

2. Improving Code Quality

3. Working With Less Frequently Used Technologies

4. More Efficient Administrative Work in the Console Using CLI Functions

Tool Limitations Guidelines

Since GitHub Copilot is based on generative AI, you must always remember that it may generate incorrect code or responses. Therefore, when using the tool, you must be aware of potential limitations and apply the principle of limited trust and verification. The main limitations are presented in the table below.

Limitation Description
Limited scope of knowledge The tool is based on code found in GitHub repositories. Some problems, or complex structures, languages or data notations, have poor representation in the training sets
Dynamic development and features in the beta phase The tool is developing very dynamically. Patches and updates appear every week or every several weeks, which indicates that many elements of the tool are not working properly. Some functionalities, such as GitHub Copilot CLI, are still in beta
Inaccurate code The tool provider informs that the generated code may not meet the user’s expectations, may not solve the actual problem, and may contain errors
Inaccurate chat responses When using chat, the accuracy of the answer depends largely on the question or command formulated. The documentation says that “Copilot Chat is not designed to answer non-coding questions”, so there are possible answers, especially in areas not strictly related to the code (design, etc.), that will not be appropriate or even sensible
Dangerous code The training set (repositories) may also contain code elements that violate security rules, both in the security and safety sense, such as API keys, network scanning, IP addresses, code that overloads resources or causes memory leaks, etc.


To minimize the negative impact of the identified GitHub Copilot limitations, you should always:

Important: Never deploy the code generated by GitHub Copilot to production environments without performing the above checks.

Configuration Guidelines

In this section, we’ll present the basic information regarding the pricing plans (with advantages and disadvantages for each option, as seen from the perspective of our intended goals) and personal account configuration (for both GitHub Copilot and the IntelliJ IDEA plugin). 

Pricing Plans

GitHub Copilot offers three subscription plans with different scopes of offered functionality and cost. In our case, two plans were worth considering: Copilot Individual or Copilot Business. The Copilot Enterprise plan additionally offers access to chat via the github.com website and generating summaries for pull requests, which was unimportant for our assumed goals (but it may be different in your case). Both plans’ main advantages and disadvantages are presented in the table below.

Plan Advantages Disadvantages
GitHub Copilot Individual Lower cost at $10/month/user


Offers the key functionality required to achieve the intended goals

Lack of control over tool configuration and user access by the organization
GitHub Copilot Business Offers the key functionality required to achieve the intended goals


Control over tool configuration and user access by the organization

Higher cost at $19/month/user


In our case, Copilot Business was the better option, especially because it allows full control over the configuration and access to the tool for developers in the team. If you’re working on your own, the Copilot Individual plan might be enough.

Account Configuration

You can configure GitHub Copilot when purchasing a subscription plan, and the settings can also be changed after activating the account in the organization’s account settings on GitHub. At the account level, there were two key parameters for our use case to configure in GitHub Copilot, described in the table below.

Option name Description Recommended settings
Suggestions matching public code Available options:


Allowed and  Blocked

Determines whether to show or to block code suggestions that overlap around 150 lines with public code

Blocked


This option reduces the risk of duplicating code from public repositories, thus reducing the uncertainty about the copyright ownership of the code

Allow GitHub to use my code snippets for product improvements Available options: Yes and No


Determines whether GitHub, its affiliates, and third parties may use user code snippets to explore and improve GitHub Copilot suggestions, related product models, and features

No


If you plan to use GitHub Copilot for commercial purposes, GitHub and its associated entities should not use user code due to copyright considerations


Here is a detailed description and instructions for changing configuration options in your GitHub account. 

IntelliJ IDEA Plugin Configuration

To enable GitHub Copilot in the IntelliJ IDEA IDE, you must install the GitHub Copilot extension from the Visual Studio Code marketplace. Installation is done via the IDE in the plugin settings. After installation, log in to your GitHub account with your device code. You can find detailed instructions for installing and updating the plugin here.

The GitHub Copilot plugin for the IntelliJ IDEA IDE offers the ability to configure the following things:

In our case, using the default plugin settings was recommended because they ensure good working comfort and are compatible with the existing tool documentation. Any changes to the configuration can be made by each user according to their own preferences.

GitHub Copilot Tutorial

Our GitHub Copilot plugin settings in IntelliJ IDEA
GitHub Copilot Tutorial
Our keymap settings for GitHub Copilot in IntelliJ IDEA

How To Use GitHub Copilot in IntelliJ

Here are some guidelines for using key functionalities that will help you use the GitHub Copilot tool optimally.

Generating Application Code

When To Use

How To Use

GitHub Copilot Tutorial

GitHub Copilot Tutorial

GitHub Copilot Tutorial

Writing Unit Tests

When To Use

How To Use

GitHub Copilot Tutorial

GitHub Copilot Tutorial

Generating SQL Queries and Stored Procedures

When To Use

How To Use

GitHub Copilot Tutorial

Creating OpenShift Configuration or Other Configuration Files

When To Use

How To Use

GitHub Copilot Tutorial

GitHub Copilot Tutorial

Using the BASH Console

When To Use

How To Use

Command Example Result
gh copilot suggest  # gh copilot suggest “find IP number in text file” grep -E -o ‘([0-9]{1,3}\.){3}[0-9]{1,3}’ <filename> 
gh copilot explain  # gh copilot explain “curl -k” curl is used to issue web requests, e.g., download web pages                                                                         


k or –insecure allows curl to perform insecure SSL connections and transfers


How To Use GitHub Copilot Chat

We’ve written a separate chapter for the GitHub Copilot Chat – as there are several use cases worth talking about. Let’s go through them individually and discuss specific guidelines for each case.

Creating New Functionalities

When To Use

How To Use

GitHub Copilot Tutorial

Using Regular Expressions

When To Use

How To Use

GitHub Copilot Tutorial

Finding Errors in the Code

When To Use

How To Use

GitHub Copilot Tutorial

GitHub Copilot Tutorial

Explanation of Existing Code

When To Use

How To Use

GitHub Copilot Tutorial

Simplify Existing Code

When To Use

How To Use

GitHub Copilot Tutorial

The result:

GitHub Copilot Tutorial

Summary: A Powerful Tool, as Long as You’re Cautious

As you can see, GitHub Copilot can be a powerful tool in a software developer’s arsenal. It can speed up and simplify various processes and day-to-day tasks. However, as with all things related to generative AI, you can never fully trust this tool – therefore, the crucial rule is to always read, review, and test what it creates. 

 

 

 

 

Top