Table of Contents
- What is GitHub Copilot?
- How do I install Copilot?
- How do I use Copilot?
- How do I improve Copilot's suggestions?
- How do I use Copilot responsibly?
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work. It draws context from comments and code to suggest individual lines and whole functions instantly.
Install Copilot on your chosen IDE. Your GitHub account must possess a valid Copilot license for use.
- Visual Studio Code (Separate Copilot Chat Extension)
- Visual Studio (Separate Copilot Chat Extension)
- JetBrains (Separate Copilot Chat Extension)
- Vim/Neovim
GitHub Copilot provides autocomplete-style suggestions from an AI pair programmer as you code. You can receive suggestions from GitHub Copilot either by starting to write the code you want to use, or by writing a natural language comment describing what you want the code to do (Demo).
Suggestions can be accepted like traditional autocomplete tools by pressing tab
to accept.
You can configure many aspects of Copilot in your environment. See your IDE specific Docs for UX and Hotkeys.
See the Official Getting Started with GitHub Copilot page for basics and best practices.
Copilot can draw context from comments and code from the file you are working in as well as open tabs in the IDE. The more data you give Copilot the higher chance it's suggestion will be helpful for you.
- If you are writing unit tests, in additional tabs open the files of the functions you would like to write test cases for.
- If you would like to write code for a given framework, import that framework at the top of the file before writing code.
const express = require('express');
- Copilot can understand natural language, write a comment in plain english (or other verbal languages!) explaining exactly what the code you are about to write is expected to do.
- Be Specific! For example, if you want GitHub Copilot to retrieve data from an API, specify what type of data you want to retrieve, how to process the data, and what API endpoint you'd like to use.
Prompt Engineering is the practice of giving an AI model specific instructions to produce the results you want. A prompt is a sequence of text or a line of code that can trigger a response from an AI model.
- GitHub Blog: How to use GitHub Copilot: Prompts, tips, and use cases
- Visual Studio Code Youtube: Master the core principles of prompt engineering
Here are some ways to leverage Prompt Engineering with GitHub Copilot:
For example summarize what the file is doing in a comment at the top of the file. Then go deeper with more function specific comments and code.
math-utils.js
# this file contains math utilities that perform complex math functions that can be called from other parts of the application
# the primes() function takes in an array and returns the prime numbers
const primes()
# the factorial() function takes in a positive integer and returns its factorial
const factorial()
If your initial prompt does not retrieve the desired response, edit your comment with more details and examples, and try again.
Make your ask simple and specific. GitHub Copilot better understands your goal when you break things down.
In many cases Copilot can determine what a function should contain just from it's name. Chances are writing code that readable to other humans will also be more readable to Copilot.
For any given input, GitHub Copilot may offer multiple suggestions. You can select which suggestion to use, or reject all suggestions. UX and Hotkeys vary by IDE, see Docs.
GitHub Copilot boosts developer productivity, but using it responsibly still requires good developer and DevSecOps practices.
- GitHub Blog: Responsible AI pair programming with GitHub Copilot
GitHub Copilot is a pair programmer, an additive tool for you to write the best code possible. GitHub Copilot does not replace sensible Software Development Lifecycle safeguards. Pair Copilot with these practices to stay in the flow responsibly (not an exhuastive list).
- Manually test code to ensure it's working as intended
- Peer Code Review
- Automated linting
- Automated unit testing
- Static application security testing (SAST)
- Software composition analysis (SCA)
- Functional, integration, load, and penetration testing