Get new issues of The GitHub Insider in your inbox. Sign up now →
The GitHub Insider
Spoiler alert: it’s all about context  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏

Have you tried coding with AI yet? Fun fact: GitHub Copilot is now the world’s most widely-adopted developer AI tool, helping developers build up to 55% faster. 💪 But being popular doesn’t mean that plenty of us aren’t still new to the world of AI pair programming. 👶 And even the GitHub Copilot veterans among us can still benefit from a few refreshers. So, in this edition of The GitHub Insider, we’re going to tackle some best practices related to prompt engineering to help you along your merry GitHub Copilot way!

What is prompt engineering?

Before we get started, let’s define some terms. When we talk about “prompt engineering” with GitHub Copilot, what we’re talking about is how to best structure our text (or in this case, our code or code comments), so that it can be better understood by a generative AI model.

Different prompts can get you better suggestions and results. You can learn more about prompt engineering in this blog post.

Here are some of our top tips for getting the best results:

#1 Provide context to get great inline suggestions 💪

Context. Context. Context. Just like when pair programming with a real human, having information and context around a project or codebase is essential to getting the best results from GitHub Copilot. Although you can absolutely start using GitHub Copilot with a blank file, you can get even better results by doing just a few more things.

Open related files in VS Code while using GitHub Copilot. GitHub Copilot uses a technique called neighboring tabs to better understand your code. That means that having additional files open will help GitHub Copilot see the bigger picture of your project. Just having these files open will help GitHub Copilot get more context, offer better suggestions, and even code completion styles.

Provide a top-level comment in your code file. This can help GitHub Copilot understand the overall context of what you’re trying to accomplish. (Plus, it’s good practice for commenting your code, because code comments are good, actually.) This can just be a simple description of what you’re accomplishing.

Input sample code. In your open editor, copy and paste sample code that’s close to what you’re looking for. Providing just a small example can help the tool generate suggestions that match the language and tasks you’re looking to achieve. (Pro Tip ✨: You can also include sample code in a separate tab alongside your other project files.)

Be sure to check out this video for more tips and tricks. And check out this blog post for even more prompt engineering goodies!

#2: Optimize your questions for better answers 🎺

Asking questions with GitHub Copilot Chat can help you code faster while staying in the flow. It’s pretty dang cool. There are several things you can do to optimize your experience.

Use agents and slash commands. Agents collect extra context about a codebase and with the right one, GitHub Copilot Chat can send better info to the Copilot backend. For instance, use @workspace to ask questions about your project or @vscode to learn more about VS Code features. Plus, slash commands help GitHub Copilot Chat understand your intent about your question. To learn about a code base, use /explain; to fix an issue use /fix; to create a test, use /test.

Use context variables. With the # symbol, you can add context, allowing you to get better answers to your questions.

#3: Get the most out of “ghost text” 👻

Ghost text is what we call the suggested code that GitHub Copilot offers inline (Pro tip: as of the latest version of VS Code, you can now change your ghost text font) in applications like Visual Studio Code. But sometimes, those suggestions aren’t exactly right.

By pressing CMD+ENTER (Mac) or CTRL-ENTER (Windows or Linux), you can open up the GitHub Copilot Code Suggestion window. Here, you can view the different code suggestions and accept which one fits your needs best.

If none of the suggestions are exactly what you need, experiment with your prompt/comment or preceding code.

Other resources and updates:

Burke on the VS Code team made a great video about getting up and running with GitHub Copilot in just minutes.

We’ll have even more GitHub Copilot tips, tricks, and prompt engineering best practices for you in future editions of the The GitHub Insider newsletter so stay subscribed for more!

Get started with GitHub Copilot

✨ This newsletter was written by Christina Warren and produced by Gwen Davis. ✨

More to explore 🌎

Take our prompt engineering 101 course

Uncover techniques to transform your coding comments into precise and actionable code with our introductory course.

Get started now

Subscribe to our LinkedIn newsletter 🚀

Do your best work on GitHub. Subscribe to our LinkedIn newsletter, Branching Out_.

Sign up now

Join our GitHub Copilot conversations 🤖

Visit our community forum to see what people are saying + offer your own two cents.

Visit now


The world’s leading AI-powered developer platform.