Skip to main content

Adding repository custom instructions for GitHub Copilot

Create a file in a repository that gives Copilot additional context for the work it does in that repository.

Hinweis

This feature is currently in public preview and is subject to change.

This version of this article is for using repository custom instructions on the GitHub website. Click the tabs above for information on using custom instructions in other environments.

About repository custom instructions for Copilot

Repository custom instructions let you provide Copilot with repository-specific guidance and preferences.

Repository custom instructions are currently supported for:

  • Copilot Chat in VS Code
  • Copilot-Programmier-Agent
  • Copilot Chat in Visual Studio, JetBrains IDEs, Xcode, and on the GitHub website (copilot-instructions.md file only)
  • Copilot Code Review (copilot-instructions.md file only)

Prerequisites for repository custom instructions

  • You must have a custom instructions file (see the instructions below).

Creating a repository custom instructions file

Copilot Chat on the GitHub website and Copilot Code Review support a single .github/copilot-instructions.md custom instructions file stored in the repository.

In addition, Copilot-Programmier-Agent supports one or more .instructions.md files stored within .github/instructions in the repository. Each file can specify applyTo frontmatter to define what files or directories its instructions apply to.

Using a single .github/copilot-instructions.md file

  1. In the root of your repository, create a file named .github/copilot-instructions.md.

    Create the .github directory if it does not already exist.

  2. Add natural language instructions to the file, in Markdown format.

    Whitespace between instructions is ignored, so the instructions can be written as a single paragraph, each on a new line, or separated by blank lines for legibility.

Using one or more .instructions.md files

  1. Create the .github/instructions directory if it does not already exist.

  2. Create one or more .instructions.md files, adding natural language instructions to the file(s).

    Whitespace between instructions is ignored, so the instructions can be written as a single paragraph, each on a new line, or separated by blank lines for legibility.

  3. Specify what files or directories the instructions apply to by adding applyTo frontmatter to the Markdown files, using glob syntax.

    ---
    applyTo: "app/models/**/*.rb"
    ---
    
    Add custom instructions here
    

    To apply the instructions to all files, use the ** pattern.

Did you successfully add a custom instructions file to your repository?

Yes No

Writing effective repository custom instructions

The instructions you add to your custom instruction file(s) should be short, self-contained statements that provide Copilot with relevant information to help it work in this repository. Because the instructions are sent with every chat message, they should be broadly applicable to most requests you will make in the context of the repository.

The exact structure you utilize for your instructions file(s) will vary by project and need, but the following guidelines provide a good starting point:

  • Provide an overview of the project you're working on, including its purpose, goals, and any relevant background information.
  • Include the folder structure of the repository, including any important directories or files that are relevant to the project.
  • Specify the coding standards and conventions that should be followed, such as naming conventions, formatting rules, and best practices.
  • Include any specific tools, libraries, or frameworks that are used in the project, along with any relevant version numbers or configurations.

The following instructions file(s) is an example of these practices in action:

# Project Overview

This project is a web application that allows users to manage their tasks and to-do lists. It is built using React and Node.js, and uses MongoDB for data storage.

## Folder Structure

- `/src`: Contains the source code for the frontend.
- `/server`: Contains the source code for the Node.js backend.
- `/docs`: Contains documentation for the project, including API specifications and user guides.

## Libraries and Frameworks

- React and Tailwind CSS for the frontend.
- Node.js and Express for the backend.
- MongoDB for data storage.

## Coding Standards

- Use semicolons at the end of each statement.
- Use single quotes for strings.
- Use function based components in React.
- Use arrow functions for callbacks.

## UI guidelines

- A toggle is provided to switch between light and dark mode.
- Application should have a modern and clean design.

You should also consider the size and complexity of your repository. The following types of instructions may work for a small repository with only a few contributors, but for a large and diverse repository, these may cause problems:

  • Requests to refer to external resources when formulating a response
  • Instructions to answer in a particular style
  • Requests to always respond with a certain level of detail

For example, the following instructions may not have the intended results:

Always conform to the coding styles defined in styleguide.md in repo my-org/my-repo when generating code.

Use @terminal when answering questions about Git.

Answer all questions in the style of a friendly colleague, using informal language.

Answer all questions in less than 1000 characters, and words of no more than 12 characters.

Repository custom instructions in use

The instructions in the file(s) are available for use by Copilot Chat as soon as you save the file(s). The complete set of instructions will be automatically added to requests that you submit to Copilot in the context of that repository. For example, they are added to the prompt you submit to Copilot Chat.

In Copilot Chat's immersive view (github.com/copilot), you can start a conversation that uses repository custom instructions by adding, as an attachment, the repository that contains the instructions file.

Whenever repository custom instructions are used by Copilot Chat, the instructions file is added as a reference for the response that's generated. To find out whether repository custom instructions were used, expand the list of references at the top of a chat response in the Chat panel and check whether the .github/copilot-instructions.md file is listed.

Screenshot of an expanded References list, showing the 'copilot-instructions.md' file highlighted with a dark orange outline.

You can click the reference to open the file.

Hinweis

  • Es ist möglich, dass mehrere Arten von benutzerdefinierten Anweisungen auf eine Unterhaltung angewendet werden. Persönliche Anweisungen haben höchste Priorität, gefolgt von Repository-Anweisungen und Organisationsanweisungen mit der niedrigsten Priorität. Alle Gruppen relevanter Anweisungen werden jedoch weiterhin kombiniert und für Copilot Chat bereitgestellt.
  • Nach Möglichkeit solltest du vermeiden, in Konflikt stehende Anweisungsgruppen bereitzustellen. Wenn du Bedenken hinsichtlich der Antwortqualität hast, kannst du Repositoryanweisungen auch vorübergehend deaktivieren. Weitere Informationen findest du unter Adding repository custom instructions for GitHub Copilot.

Aktivieren oder Deaktivieren benutzerdefinierter Repositoryanweisungen

Du kannst auswählen, ob Copilot repositorybasierte benutzerdefinierte Anweisungen verwenden soll.

Aktivieren oder Deaktivieren benutzerdefinierter Anweisungen für Copilot Chat

Benutzerdefinierte Anweisungen sind standardmäßig für Copilot Chat aktiviert, sie können jedoch jederzeit deaktiviert oder erneut aktiviert werden. Dies gilt für deine eigene Verwendung von Copilot Chat und betrifft keine anderen Benutzenden.

  1. On GitHub.com, do one of the following:

    • Go to a repository with a custom instructions file and open the assistive chat panel.
    • Go to the immersive view of Copilot Chat (github.com/copilot) and attach a repository that contains a custom instructions file.
  2. Click the button at the top of the Chat panel, or the top right of the immersive page.

  3. Click Disable custom instructions or Enable custom instructions.

    Hinweis

    You will only see these options in the context of a repository that contains a custom instructions file.

Your choice persists, for all repositories containing a custom instructions file, until you change it.

Aktivieren oder Deaktivieren benutzerdefinierter Anweisungen für Copilot Code Review

Benutzerdefinierte Anweisungen sind für Copilot Code Review standardmäßig aktiviert. Du kannst sie aber in den Repositoryeinstellungen auf GitHub.com deaktivieren oder erneut aktivieren. Dies gilt für die Nutzung benutzerdefinierter Anweisungen durch Copilot für alle Reviews, die für dieses Repository durchgeführt werden.

  1. Klicke im Abschnitt „Code & automation“ der Randleiste auf Copilot und dann auf Code review.
  2. Aktiviere oder deaktiviere die Option „Use custom instructions when reviewing pull requests“ mithilfe der Umschaltfläche.