Skip to main content
January 23, 2024

GitHub Copilot: Your best programming partner

Generative AI coding tools are transforming how developers approach their code creation tasks. We’ve previously talked about Microsoft Copilot, its benefits, and how it is increasing productivity, access to data, and extending user knowledge.

Now, GitHub has also included using this intelligent assistant to create code. We explain what it is, how to use it and the main use cases..  

What is GitHub Copilot

GitHub Copilot is an artificial intelligence tool that works as an intelligent assistant designed to help developers create code.

It works through auto-completion, meaning that when a user starts writing code, GitHub Copilot makes suggestions on how the completed code would look.

It is based on the GPT-3 language, published by OpenAI, which uses deep learning strategies to understand human texts or compose its own texts. Thus, the AI uses algorithms, collects huge amounts of data, and creates new content from it. In this case, it obtains publicly available code information from various repositories and recognizes numerous programming languages such as Go, Java, Python, TypeScript, etc.  

How to use GitHub Copilot

To start using GitHub Copilot, you should know that it can be managed through personal accounts with GitHub Copilot for Individuals or enterprise accounts such as GitHub Copilot for Business.

Before you start using it, you’ll need to set up a test through the “Settings” tab > “Code, scheduling and automation” > GitHub Copilot.

Once you’re on the GitHub Copilot configuration page, click “Enable GitHub Copilot” > “Continue to get access to Copilot” > payment details > Submit > Save and get started. 

View a suggestion

The next thing you need to do is install the GitHub Copilot extension for Visual Studio Code. To get your first hint, open Visual Studio, create a new file, and type in the function header. Copilot will automatically suggest the full-function body in dimmed text. To accept the suggestion, press Tab. 

Alternative suggestions

You may also not want any of the initial suggestions offered by GitHub Copilot, so you can opt to get multiple suggestions in a new tab. Just press Ctrl+ Enter.

And just as with the first suggestion, press Tab to accept or Esc to reject. 

Generate suggestions through comments

There is the option to describe something you want to do using natural language within a comment, and Copilot will suggest the code to achieve your goal: create file > write the comment, and you will receive the suggested implementation of the function.  

Using a framework

You can also use Copilot to generate API and framework suggestions, such as creating a simple Express server that returns the current time.

Just create a new JavaScript file, type the comment “// Express server on port 3000,” and then press “Enter.” This will suggest an implementation of the Express application. Accept each line and type the comment “// Return the current time,” and GitHub Copilot will suggest an implementation for the default driver.  

GitHub Copilot | Best Practices

As mentioned above, GitHub Copilot offers suggestions from billions of lines of open-source code. The result is that it can create unsafe coding patterns, errors, or references to APIs or obsolete expressions, so the developer is ultimately responsible for ensuring the security and quality of the code.

That is why the platform itself recommends taking the same precautions as when using any code that is not your own: rigorous testing, IP examination, and monitoring for security vulnerabilities.

With that in mind, here are some examples of best practices when using GitHub Copilot: 

  1. Prepare the scenario with a high-level goal: this is most useful if you have a blank file or an empty codebase. That is, if GitHub Copilot has no context for what you want to build, you should prepare the scenario with a general description before you start with the details. Think about how you would explain it to a person in a normal conversation: how to break down the problem to be tackled, how to do it together, and so on.
  2. Ask simple and specific questions: once you give the helper the main objective, tell them the steps they need to take to achieve it. Copilot will understand it better if the process is broken down and divided (as if it were a recipe for food). This way, it will be able to generate the code at each step and not all at once.
  3. Give it an example or two: as with humans, learning by example is much easier for GitHub Copilot to understand, so make it as simple and clear as possible. 
  4. Experiment with their directions: If you don’t get what you wanted on the first try, re-craft your message following the best practices mentioned above. Either with more specific details, setting boundaries, or outlining what you want the function to do.
  5. Keep a couple of relevant tabs open: GitHub Copilot uses a technique called neighboring tabs, which allows you to contextualize processed code across all open files in the IDE rather than just opening the file you’re working on. So, to help the wizard contextualize your code, we recommend that you have one or two tabs open.
  6. Review everything: in the same way that you review your code regularly, AI-generated code should always be evaluated, analyzed, and validated. Given the sheer scale of LLMs, they might generate a sequence of code that doesn’t even exist yet, and you will be the final filter that gives it the thumbs up.  

Github Copilot Use Cases

GitHub Copilot offers numerous features to assist you in your work with code, and there are still many more to come thanks to the constant updates the tool is constantly releasing. Here are the most important ones: 

  • Converting comments to code: we have discussed this above, and the fact is that, thanks to using GPT-3, it has been trained with a lot of public source code. This means that it is as good at writing natural language as it is at writing code, so once given the instructions, it can move through the code we’ve asked it to write.
  • Create unit tests: Copilot takes the monotony out of writing unit tests. You can work with an AS:NET Core API that returns information about an element; you start writing a test function, and Copilot will generate the assertions.
  • Create a SQL query: To create SQL-based C# code with Copilot, we just need to display the schema as statements and then write an embedded query in C#.

GitHub Copilot X

This is the future version of GitHub Copilot and will be a step forward in AI-supported programming. It is still in testing, and no release date is known, but they are already working on its design and creating new features.

It features chat and terminal interfaces, support for pull requests, and early adoption of GPT-4, and it is already positioned as the future of AI-powered software development.

Key features include: 

  • Context-aware conversations: if you can’t solve a problem, you can ask Copilot to explain a piece of code. Also, if you find a bug, it can fix it or generate unit tests so you can rebuild what comes next.
  • Documents tailored to your needs: you can spend less time searching and more time learning, as Copilot will give you customized answers based on written documentation and online quotes.
  • Pull requests that tell a story: Copilot tracks your work, suggests descriptions, and helps reviewers reason about your changes with a code tutorial.
  • Take control of your CLI: if you want to remove a tag or need help with your scripts or shell commands, just explain it to Copilot. 

GitHub Copilot for Business

Already, millions of developers are relying on GitHub Copilot to build software. Research has found that GitHub Copilot helps developers code faster (96%), focus on solving bigger problems (74%), stay in the flow longer, and feel more satisfied with their work (88%).

With this service, access to GitHub Copilot can be managed within a company. It uses data from the file content and additional sources to improve its functionality. This process aims to improve the service and involves the collection and analysis of certain information: 

  • Evaluation of the impact of GitHub Coplito on users by measuring its positive effects and benefits.
  • Data helps optimize and improve the algorithms used to rank and sort suggestions, improving the overall user experience.
  • Detecting abuse and policy violations by examining the data for investigation and research.
  • Data is used to conduct experiments and research related to developers and their use of developer tools and services.

GitHub Framework

If you need a partner to discover the full potential of GitHub Copilot, Plain Concepts can make it easy for you. 

  • We are the first partner in Spain accredited by GitHub.
  • We have been working for more than 17 years in the Agile culture, a benchmark in the DevOps community.
  • We have a team of more than 350 senior engineers specialized in App Innovation and DevOps.
  • AMMP accredited.
  • DevSecOps with MVPs.  

 

In addition, we don’t stop at certifications, and we offer you an exclusive GitHub Adoption Framework so that you can find the service that best suits your needs from the best experts.

You can train in GitHub Actions, GitHub for developers, GitHub Admin, GitHub API, GitHub Copilot, GitHub Advanced Security, and Advanced Security for DevOps.   

Don’t wait any longer and contact us to become a GitHub Copilot expert!

Elena Canorea
Author
Elena Canorea
Communications Lead