How do you write prompts for GitHub Copilot that give better code?
By IA Business Lab · Updated 2026-11-21
Give it context: a clear comment with the goal, expected inputs and outputs, language or framework and constraints. Ask in small steps, always review the code it suggests and test it before accepting. Copilot is an assistant: responsibility for the result stays with you.
Why context changes the result
Copilot suggests code from what it can see: the open file, comments, function names and, depending on the setup, other files in the project. An ambiguous name produces an ambiguous suggestion. Writing a clear intent is the simplest way to improve what you get.
Structure of a good request
- Goal: what the code must do, in one sentence.
- Inputs and outputs: types, formats and an example.
- Environment: language, version, allowed libraries.
- Constraints: performance, style, edge cases, what it must not do.
- Small steps: ask for one function at a time, not a whole application.
Example: from a vague request to a clear one
Vague: "function for dates". Clear: "Write a Python 3 function that takes a date as a DD/MM/YYYY string and returns how many days remain until today. If the format is invalid, raise ValueError. Include two usage examples."
The second version defines the language, input, output and error handling, so it leaves little room for guesswork.
Good habits when accepting suggestions
- Read the code before accepting it; do not accept what you do not understand.
- Run tests, including edge cases.
- Ask it to explain a suggestion or to write the tests.
- Check licenses, security and handling of sensitive data.
- Do not paste credentials or private data into comments.
Common mistakes
- Asking for too much in one step.
- Trusting the code because it compiles.
- Giving no project context.
- Accepting dependencies you do not know.
A suggested routine
Write the comment, look at the suggestion, adjust the request if it does not match, accept only what you understand and test it. With practice you will notice which kinds of requests work best.
Frequently asked questions
Does Copilot replace a programmer?
No: it speeds up repetitive tasks and proposes drafts, but you still review, test and decide.
Does it work in any language?
It works best in widely used languages and libraries; quality can vary elsewhere.
Can I use it with company code?
It depends on your organization's policies and the plan's privacy settings; check them first.
Sources and further reading
Go deeper with the book
Mastering Your AI Pair Programmer: A Deep Dive into GitHub Copilot — English edition · PDF eBook · instant download · sold on Gumroad · $11.99 USD. According to its official description: A deep dive into GitHub Copilot: installation and setup, how it works, writing effective prompts, autocomplete and Copilot Chat, unit testing, debugging, refactoring, learning new languages, security best practices, teams and enterprises, and the future of… The examples in this guide are illustrative and are not necessarily from the book.
Get the book on Gumroad · $11.99 USDFull book page →
Educational content. Not professional advice. See the full store →