Get startedGet started for free

Customizing Copilot

1. Customizing Copilot

Welcome to a new chapter!

2. Training Copilot with custom instructions

GitHub Copilot isn't just reactive—it's configurable.

3. Training Copilot with custom instructions

You can teach it how you want code to be written in your project, and it will remember, without needing to be reminded in every chat.

4. Training Copilot with custom instructions

This is possible

5. Training Copilot with custom instructions

through something called custom instructions.

6. How custom instructions work

Custom instructions let you define coding conventions, tool preferences, and project context up front, so Copilot generates consistent code that fits your standards. For example, if your project uses Python with type hints, pytest, and Google-style docstrings,

7. How custom instructions work

you can tell Copilot that once, and it will follow those conventions in every suggestion.

8. How to define custom instructions

So, how can you define custom instructions? Your project can include a special file called copilot-instructions.md that's placed inside a .github folder. Inside it, you describe your coding guidelines and context. For example: Use type hints for all functions, follow PEP8, use snake case naming, write docstrings using Google-style format, use pytest, include at least one test per function, and so on.

9. What makes an effective instruction

There's no specific structure for the instructions file, but each statement should be short, specific, self-contained, and add context or relevant information for Copilot to apply automatically. Some types of instructions are unlikely to work as intended, especially if they refer to external documents or repositories, specific tones or writing styles, arbitrary limits on detail or formatting.

10. Ineffective instructions examples

For example, these instructions will likely be ignored or produce inconsistent results: "Conform to the coding styles defined in styleguide.md in repo my-org/my-repo", "Answer in the style of a friendly colleague, using informal language", "Answer in fewer than 1,000 characters."

11. Ineffective instructions examples

Instead, focus on self-contained statements that give Copilot helpful, project-relevant context.

12. How to enable custom instructions

Once this file is saved, Copilot automatically includes it as part of the prompt, behind the scenes. To enable this behavior in VS Code,

13. How to enable custom instructions

ensure the Use Instruction Files setting is turned on.

14. Using multiple instruction files

You can also use multiple instruction files under .github/instructions/ and apply them selectively to certain files or folders using an applyTo block.

15. Using multiple instruction files

This gives you even more control over where specific instructions apply.

16. Using multiple instruction files

For example, you might apply one instruction file to your /api folder and another to /tests.

17. Setting organization-level instructions

If you use Copilot for Business or Enterprise, organization admins can define organization-level instructions. These are managed directly in GitHub.

18. Setting organization-level instructions

Admins can use them to apply company-wide rules like use internal tools, enforce specific libraries, apply consistent style, warn on deprecated patterns, and so on.

19. Multi-level instructions priority

What happens if you have instructions at multiple levels? Copilot merges them. But if there's a conflict, personal instructions override project ones, and project ones override organization-wide ones. So you can still fine-tune behavior on a per-user or per-project basis.

20. The importance of custom instructions

So, how does this help with prompting and context? Try asking Copilot: "Write a function that calculates the average of a list of numbers." If your instruction file includes guidance about type hints and docstrings, Copilot should apply those even if you didn't mention them in the prompt.

21. The importance of custom instructions

It's a subtle but powerful way to shape how Copilot works, without repeating yourself!

22. Let's practice!

With custom instructions, you're not just prompting Copilot, you're training it. Now, let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.