Note
-
此功能目前为 公共预览版,可能会更改。
-
Visual Studio、VS Code 和 GitHub 网站上的 Copilot Chat 目前支持自定义说明。
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 GitHub Copilot Chat
GitHub Copilot can provide chat responses that are tailored to the way your team works, the tools you use, or the specifics of your project, if you provide it with enough context to do so. Instead of repeatedly adding this contextual detail to your chat questions, you can create a file in your repository that automatically adds this information for you. The additional information is not displayed in the chat, but is available to Copilot to allow it to generate higher quality responses.
You can also create personal custom instructions, which apply to conversations you, as a user, have with Copilot Chat across GitHub. This differs from repository custom instructions, which apply to conversations in the context of a single repository. For more information on personal instructions, see 为 GitHub Copilot 添加个人自定义说明.
Prerequisites
- A custom instructions file (see the instructions below).
- Your personal choice of whether to use custom instructions must be set to enabled. This is enabled by default. See Enabling or disabling repository custom instructions later in this article.
- During the 公共预览版, if you have a Copilot Business subscription, then the organization from which you receive your subscription must have the Opt in to preview features setting enabled. See 管理组织中的 Copilot 策略.
Creating a repository custom instructions file
-
In the root of your repository, create a file named
.github/copilot-instructions.md
.Create the
.github
directory if it does not already exist. -
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.
Sample instructions
This example of a .github/copilot-instructions.md
file contains three instructions that will be added to all chat questions.
We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.
We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.
Our team uses Jira for tracking items of work.
Writing effective repository custom instructions
The instructions you add to the .github/copilot-instructions.md
file should be short, self-contained statements that add context or relevant information to supplement users' chat questions.
The following types of instructions are unlikely to work as desired and may cause problems with other areas of Copilot:
- 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
The following instructions are therefore unlikely to have the intended result:
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 .github/copilot-instructions.md
file are available for use by Copilot Chat as soon as you save the file. The complete set of instructions will be automatically added to chat prompts that relate to the repository containing the instructions file.
In immersive mode (the https://github.com/copilot page), you can start a conversation that uses custom instructions by adding, as an attachment, the repository that contains the instructions file.
Custom instructions are not visible in Copilot Chat, but you can verify that they are being used by Copilot by expanding the list of references at the top of a chat response in the Chat panel. If custom instructions were added to the prompt that was sent to the model, the .github/copilot-instructions.md
file is listed as a reference.
You can click the reference to open the file.
Note
个人自定义说明优先于存储库自定义说明,但提供给 Copilot Chat 的最终提示中同时包含了两者。 尽可能避免提供相互冲突的个人说明和存储库说明。 如果顾虑响应质量,也可以选择暂时禁用存储库说明。 有关详细信息,请参阅“Adding repository custom instructions for GitHub Copilot”。
Enabling or disabling repository custom instructions
You can choose whether or not to have custom instructions added to your chat questions.
- Click the button at the top of the Chat panel, or the top right of the immersive page.
- Click Disable custom instructions or Enable custom instructions.
Your choice persists until you change it.