Instruction Files: Keep GitHub Copilot Consistent Across Your Project

AI-generated code is most valuable when it follows your project's conventions. Instead of repeating coding rules in every prompt, you can store them in an instruction file. GitHub Copilot automatically uses these instructions when generating code, helping produce more consistent results across the repository.

What instruction files are

Instruction files define general project guidance, such as:

  • Coding style
  • Naming conventions
  • Architecture preferences
  • Testing requirements
  • Documentation standards

Unlike prompts, instruction files do not perform actions. They simply provide persistent context for Copilot.

How to create an instruction file

  1. Create a .github/instructions folder if it does not already exist.
  2. Create a Markdown instruction file.
  3. Add the development rules you want Copilot to follow.
  4. Commit the file with your repository so the whole team benefits.

Example

# .github/instructions/coding.instructions.md

## Coding Standards

- Use C# 13 features where appropriate.
- Prefer dependency injection.
- Write XML documentation for public APIs.
- Use async/await for I/O operations.
- Add unit tests for new functionality.

Once saved, Copilot can use these guidelines whenever it generates code for your project.

Best practices

  • Keep instructions concise.
  • Separate unrelated topics into multiple files.
  • Review them as your project evolves.
  • Avoid conflicting rules.
instructions
copilot
standards
development
github

Comments