Skip to main content
Before you set up the full project, these quick wins make GitHub Copilot produce higher-quality, project-consistent code immediately. The most impactful is a repository-level, file-based Copilot configuration that instructs the model how to generate code for this specific project.

Repository-level Copilot instructions

Repository-level Copilot instructions live at .github/copilot-instructions.md. Adding this file lets you define project-specific coding standards (style, naming, import order, docstrings, etc.) that GitHub Copilot will consult when generating completions and Chat responses.
Place the file at .github/copilot-instructions.md in your repository root so GitHub Copilot can find it automatically.
Create the folder (example shell session):
Then add .github/copilot-instructions.md. A practical sample that instructs Copilot to follow PEP 8 and common Python best practices:
What this file does is tell Copilot how you’d like code to be produced for this repository. You can be as strict or as lenient as you prefer.

Example: PEP 8–compliant function

An example function that follows the guidelines above:

How Copilot uses repository instructions

  • Copilot consults .github/copilot-instructions.md to shape generated code, including docstrings, naming, formatting, and import order.
  • The instructions are most effective for Chat completions and for full-file or multi-line completions. Inline suggestions may still deviate.
  • If a completion doesn’t meet your standards, use Copilot Chat or the Completions panel to get more controlled outputs.

Testing with Copilot Chat

Open Copilot Chat in your editor and prompt it to generate a function or module. Chat often respects docstrings, typing, and other rules from the repository instructions. Example produced by Copilot Chat (adhering to the instructions):
The Completions Panel lets you compare multiple candidate suggestions and pick the best one — useful when you want to select a particular style or a candidate that includes complete docstrings and typing. Prompt example: “Create square of a number” One candidate you might accept:
Keyboard shortcuts and keybindings speed up accepting suggestions and toggling chat/completions UI. On macOS or Windows/Linux, customize these in your editor keybindings.
A screenshot of a code editor's keyboard shortcuts/settings pane filtered for "copilot". It lists GitHub Copilot commands, their keybindings, activation conditions ("When") and source.

Common Copilot commands and IDs

Use the table below to quickly map common Copilot UI commands to their command palette IDs (useful for customizing keybindings or automation):

Model selection and editor context

A dark-themed code editor window showing an AI/Copilot chat pane and a model-selection dropdown with "GPT 4o" highlighted. A left-side terminal tab labeled "zsh" and the editor status bar are also visible.
  • Copilot can run on different underlying models. If available, you can change the model from the Copilot pane — model choice affects style, reasoning, and cost.
  • Try a few models to determine which produces the most useful, concise, or explainable output for your workflow.
  • Always ensure the file you want help with (for example, main.py) is active — Copilot uses open files and editor context to form suggestions.
Context window considerations
  • The Copilot context window is finite. Opening many files or working in very large repositories increases the visible context and may dilute suggestion quality.
  • Best practice: close unrelated files and open only the files relevant to your current task. This keeps the editor context focused and helps Copilot produce more relevant suggestions.

Best practices summary

  • Add .github/copilot-instructions.md to define project-specific rules.
  • Keep your editor focused on the current file(s) to reduce noisy context.
  • Use Copilot Chat and the Completions Panel when you need more structured, multi-line, or documented outputs.
  • Customize keybindings for faster acceptance and navigation of suggestions.
Do not store secrets or sensitive data in .github/copilot-instructions.md. This file is a repository asset and will be visible to collaborators — treat it like other repository configuration files.

Next steps

With repository-level instructions and a focused editor context, you can:
  • Use comment-driven development to generate functions, docstrings, and tests.
  • Ask Copilot Chat to scaffold modules or sample data generators.
  • Iterate on the repository instructions over time to tune the style and constraints Copilot follows.
References

Watch Video