A Prompt Engineering Guide for GitHub Copilot

Unlock the full potential of GitHub Copilot and maximize your productivity with GitHub's AI using our comprehensive guide to prompt engineering.

Table of Contents
Flexible work is just a click away

GitHub Copilot is a new artificial intelligence (AI) software tool offered in partnership with OpenAI and Microsoft. It's a coding assistant that fits into a developer's integrated development environment (IDE) and allows them to use generative AI to generate code snippets and troubleshoot errors.

Although earlier coding assistance tools (such as IntelliSense) have helped programmers code faster, they've been limited in their usefulness because of the lack of AI integration.

Generative AI helps Copilot stand apart because of its integration with large language models (LLM). GPT, the LLM Copilot uses, has read an enormous amount of programming code to process many programming languages, algorithms, and software development concepts. This information helps Copilot generate programming code for developers without relying on predefined rules.

But to get the most out of Copilot, software engineers must understand how to install it in their environment and use it correctly—something you can do with prompt engineering.

This guide will explain how to set up Copilot for prompt engineering and use prompt engineering to generate the correct coding style. It will also explore best practices and advanced prompt engineering techniques to get even more from Copilot.

Understanding prompt engineering

Prompt engineering involves crafting inputs to large language models (LLMs) using natural language to produce better outputs. This iterative process typically includes the following steps:

  1. Initial prompt. Start with a basic prompt to see initial results.
  2. Result analysis. Review the output to identify areas for improvement.
  3. Prompt refinement. Based on the analysis, make minor changes to your language and add details to enhance the next prompt.
  4. Output modification. Observe how these changes affect the AI's response.
  5. Iteration. Repeat steps 2-4 as necessary to achieve the desired output.

This approach is similar to few-shot learning in AI, where a system adapts to new tasks using minimal examples. By starting with a more general prompt, the prompter allows the AI to apply its broad knowledge base more flexibly. The prompter can then gradually add specific context and details, refining the AI's output through successive prompt iterations.

This approach contrasts with zero-shot learning, where an AI system attempts to perform a task or classify data it has never encountered during training, relying solely on its pre-existing knowledge and the task description provided in the prompt.

How the Copilot AI model works

GitHub Copilot works using generative AI technology. It's based on the LLM GPT. The original version of Copilot used a fine-tuned GPT model called OpenAI Codex (now discontinued). Since then, it has transitioned to use GPT-4.

These AI models work by digesting large amounts of data. They train on text datasets from across the web, including plain text documents and source code from public open-source repositories. They then use machine learning to identify patterns in data to produce output for users.

Because of that AI process, GPT can analyze users' requests when they ask for programming code and output it in their chosen language. It uses natural language processing (NLP) to process the meaning of input text and predict what the user wants to see.

How to use GitHub Copilot for prompt engineering

Making the most of Copilot means installing and navigating it properly in your code editor. Let's look at how to install Copilot, navigate it, and prompt it to generate usable code.

1. Set up GitHub Copilot

Setting up Copilot starts with signing into your GitHub.com account. You need an activated account to sign up for a subscription, so log into your account or create one. Once you create an account, you can sign up for a free trial or paid subscription.

Once complete, you can install Copilot in your code editor. In this case, we'll install Copilot in Visual Studio Code. Open Visual Studio Code and click on the extensions menu. Search for Github Copilot in the extensions screen and click install. (It appears as "uninstall" in the image below since we've already installed it.)

Set up GitHub Copilot

Once installed, the extension will ask you to activate your Copilot subscription in Visual Studio. Click the link offered, and you'll head to the GitHub website to activate Copilot in your editor.

You're ready to start using Copilot at this point.

2. Navigate the Copilot interface

After activating your account, you'll see a status icon at the bottom right of the screen. Click it to make sure Copilot is activated.

Navigate the Copilot Interface

The primary way many developers use Copilot is directly in the code editor using keyboard shortcuts. Press "Ctrl + I" on Windows or "Command + I" on macOS on your keyboard to bring up the Copilot inline chat. Then, ask Copilot to do a task for you.

Development

Copilot will come up with a suggestion for you to accept or discard. You can also rate it to help improve Copilot. If you want Copilot to try again, click the retry button next to discard.

Copilot suggestion

You can also type commands when the input window comes up. A few common options are:

  • /doc. Add documentation to the code
  • /explain. Explain the selected code.
  • /fix. Look for errors in the code and suggest solutions.
  • /test. Generate tests for the code.

You can take more actions in the code editor, so browse the complete list of Copilot keyboard shortcuts to learn everything. You can find them in your VSCode configuration settings. Click on the Copilot Status icon in the bottom right, as you did above, to access the menu. Once open, you'll find an option to browse the list of keyboard shortcuts.

Co editor

From there, you can familiarize yourself with the default shortcuts or change them to suit your needs.

Default shortcuts

Copilot also has a ChatGPT-like feature to chat with it using natural language. You can use this window to brainstorm ideas and perform other code-related tasks. For example, let's ask Copilot for suggestions to improve our function:

Github copilot

As you can see, Copilot adds error handling to avoid problems if the user enters an invalid input.

3. Craft effective code prompts

Writing clear and precise prompts will help you guide Copilot in producing output relevant to your current problem without mistakes. You'll need to experiment with different ways of asking questions to see what generates the best results.

For example, say you want to write a function to sort numbers. You can tell Copilot to generate a function to do this for you. But will it choose the sorting algorithm you want and the right programming language?

The "bubble sort" algorithm is one of the slowest, so you may want to explore faster sorting algorithms and let Copilot know bubble sort isn't what you want. 

Let's have Copilot write a merge sort algorithm in Python:

Craft effective code prompts

Copilot did exactly what we asked instead of determining which sorting algorithm to use on its own.

We gave Copilot the right context (an exact sorting algorithm) and good keywords (Python, sorting, merge sort, display results). If you don't like the results, you can refine your prompt to add more clarity and get results that are more aligned with your expectations.

4. Leverage AI models for prompt generation

At some point, you might find it challenging to get Copilot to generate what you want. Although AI can often handle tasks effectively, it can make errors.

You can use AI models to craft more effective prompts. AI assistance may help you identify missing context and suggest the optimal way to phrase things to produce more accurate results.

For instance, Copilot might generate an algorithm to perform a task, but it performs too slowly. You may not know what to tell it to have it produce better code.

Luckily, Copilot can offer suggestions. You can then add those suggestions as context to help Copilot understand your request.

For example, see how the following code finds the maximum number in an array:

Leverage AI Models 1

There may be a more efficient way to do this, so we asked Copilot for a suggestion.

Leverage AI Models 2

Copilot suggests using the max function in Python instead of doing things manually, resulting in a shorter function.

5. Use examples and code snippets

Providing examples and code snippets is one of the best ways to prompt Copilot to produce better results. Code snippets give AI an idea of what you're looking for, which it will then use as a building block to generate a response.

Take, for instance, a situation where you have a set of existing functions you want to build on. If you don't provide the AI with functions, it will make something up by default. When this happens, it will take more work to get the output you need.

On the other hand, providing those functions to Copilot upfront will improve the response. Let's look at a case where these functions are predefined:

Code snippet

As you can see, we asked Copilot to expand our program by creating new calculator features based on existing code. Copilot uses our example code to generate results that align with our starting code.

6. Tailor prompts to specific programming languages

Copilot isn't specific to a single programming language. It receives training data from all the languages in the GitHub repositories, so it can process all the popular languages and many of the less-used ones.

Because of that, Copilot may not produce results in your desired programming language unless specified. For example, you may be writing an SQL statement that passes the current date as a parameter. Asking Copilot gives this result:

Tailor prompt 1

This result is fine if you use MySQL or PostgreSQL, but the query differs if you use Microsoft SQL Server. Ask Copilot for the correction:

Tailor prompt 2

As another example, let's look at a JavaScript function that manipulates a textbox. You can ask Copilot to handle this for you:

Tailor prompt 3

However, in the example above, you fail to specify that you use TypeScript to make your life easier. Copilot outputs Vanilla JavaScript instead. Refine your prompt to include the right keywords:

Tailor prompt 4

7. Create your first code prompt

Now that you've gone through the steps of getting started with Copilot prompt engineering, it's time to implement them and create your first prompt.

Let's look at a short tutorial to create a simple number guess game in Python. Ask Copilot for suggestions to start:

First code attempt 1

Copilot gave us a roadmap to follow. Now, we have a set of prompts to create. The next step is creating a random number:

First code attempt 2

Copilot generates the number but includes the code to display it for us—which we don't want right now. Iterate on the prompt to try again:

First code attempt 3

This works better. Now, we can request input from the user:

First code attempt 5

Next, we can compare the two numbers and ask the user again if they aren't correct:

First code attempt 4

Copilot makes a small change to the code to account for the new request and adds additional code to check the numbers. If the numbers don’t match, the process repeats. Once the user guesses the correct number, the program finishes, and you’re done.

Best practices for prompt engineering

Several techniques are available to make the most of Copilot. Here are a few best practices to remember.

  • Since GitHub Copilot gets additional context from your codebase, keep additional files open to help it understand more about your project.
  • Use descriptive variables and function names to help Copilot understand its current context.
  • Use descriptive language for your unique use cases to avoid generic code that doesn’t suit your needs.
  • Experiment and iterate with different prompts to learn how Copilot reacts in different situations.
  • Use code comments to help Copilot’s algorithms analyze more context in code.
  • Generate code step by step to avoid Copilot veering in the wrong direction by doing large blocks of code at once.

Advanced techniques in prompt engineering

The Copilot AI tool can offer much more than brainstorming ideas and code suggestions. Try these advanced techniques to streamline your software development workflow.

  • Create boilerplate code to avoid writing the same lines of code over and over again
  • Create a file for unit tests and use Copilot to generate tests automatically
  • Browse to program errors in the editor and use GitHub Copilot chat to debug the code you have trouble with and suggest solutions
  • Ask Copilot to refactor existing code to improve its conciseness and performance
  • Chat with Copilot to brainstorm new features users may find valuable in your software’s industry
  • Request Copilot to suggest security improvements to enhance application security

Troubleshooting and FAQ

Do you have more questions or problems with Copilot? Read the common questions below to get answers.

What are the limitations of GitHub Copilot?

Although Copilot is a revolutionary AI pair programmer, it does have limitations. It can still produce incorrect and inefficient code. Its knowledge base is also limited to GPT’s cutoff date of September 2021, which means it may struggle with new languages and frameworks. There’s also the risk of introducing copyrighted and proprietary code, which requires due diligence before shipping products.

What are the advantages of prompt engineering with GitHub Copilot?

Prompt engineering gives you a chance to provide additional clues to Copilot to help it improve. With Copilot, one-shot and multi-shot prompting are integrated directly into the editor. Developers won’t need to switch back and forth between other AI tools to take advantage of AI for programming. This process leads to more accurate results and less time spent working with AI-generated code that doesn’t meet your needs. It helps you become more efficient and ship more code in less time.

What can you use GitHub Copilot with?

You can use GitHub Copilot with your desktop code editor. It’s feature-rich and compatible with VS Code. Copilot is also available for JetBrains, Neovim, and Visual Studio.

Work with code on Upwork

Prompt engineering with Copilot is the process of modifying your AI input prompts to provide additional context, keywords, and syntax to generate better results. Prompting more efficiently will help you work better with AI, become more efficient, and ship more code. Continue to iterate on your prompting techniques to learn more about how Github Copilot works and how to produce great results.

Are you a prompt engineer looking for more work? Browse Upwork to find new prompt engineering freelance jobs.

Is your business in need of prompt engineers? Browse Upwork to find prompt engineers for your next project.

Upwork does not control, operate, or sponsor the tools or services discussed in this article, which are only provided as potential options. Each reader and company should take the time to adequately analyze and determine the tools or services that would best fit their specific needs and situation.

Heading
asdassdsad
Do the work you love, your way

Author Spotlight

A Prompt Engineering Guide for GitHub Copilot
The Upwork Team

Upwork is the world’s largest human and AI-powered work marketplace that connects businesses with independent talent from across the globe. We serve everyone from one-person startups to large organizations with a powerful, trust-driven platform that enables companies and talent to work together in new ways that unlock their potential.

Latest articles

Article
Guru vs. Upwork: An In-Depth Comparison
Jul 21, 2026
Article
Grow and Scale Your Business With Freelance Talent
Jul 17, 2026
Article
The Risks of Hiring Freelancers and How To Navigate Them
Jul 15, 2026

Popular articles

Article
How To Create a Proposal On Upwork That Wins Jobs (With Examples)
Jun 24, 2026
Article
Top 9 Machine Learning Skills in 2026 To Become an ML Expert
May 8, 2026
Article
The 6 Highest-Paying Machine Learning Jobs in 2026
Apr 23, 2026
Create your freelance profile today