Skip to main content

GitHub Copilot のリポジトリ カスタム命令を追加する

Copilot Chat への質問に情報を自動的に追加するファイルをリポジトリに作成します。

メモ

この機能は現在パブリック プレビューにあり、変更される可能性があります。

Repository custom instructions are currently supported for Copilot Chat in Visual Studio, VS Code and on the GitHub website.

この記事のこのバージョンは、GitHub Web サイト上でリポジトリのカスタム命令を使うためのものです。 他の環境でカスタム指示を使う方法については、上のタブをクリックします。

GitHub Copilot Chat の応答のカスタマイズに使用できる方法の概要については、「About customizing GitHub Copilot Chat responses」をご覧ください。

GitHub Copilot Chat のリポジトリのカスタム命令について

GitHub Copilot は、チームの活動方法、使用するツール、またはプロジェクトの詳細に合わせて調整されたチャット応答を提供できます (そのために十分なコンテキストを指定した場合)。 このコンテキストの詳細をチャットの質問に繰り返し追加するのではなく、この情報を自動的に追加するファイルをリポジトリ内に作成できます。 追加情報はチャットには表示されませんが、Copilot が使用して、より高品質の応答を生成できます。

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.

リポジトリ カスタム指示の前提条件

  • カスタム指示ファイル (以下の手順を参照)。

リポジトリのカスタム命令ファイルを作成する

  1. リポジトリのルートに .github/copilot-instructions.md という名前のファイルを作成します。

    .github ディレクトリがまだ存在しない場合は作成します。

  2. Markdown 形式で自然言語の指示をファイルに追加します。

    指示と指示の間の空白は無視されるため、複数の指示を 1 つの段落に記述することも、1 行に 1 つずつ記述することもでき、読みやすくするために空白行で区切ることもできます。

指示の動作を確認するには、https://github.com/copilot に移動し、指示ファイルを含むリポジトリをアタッチして、会話を始めます。

カスタム指示ファイルをリポジトリにうまく追加できましたか?

はい いいえ

効果的なリポジトリのカスタム命令を作成する

.github/copilot-instructions.md ファイルに追加する指示は、ユーザーのチャット質問を補完するコンテキストすなわち関連情報を追加する、短い自己完結型の文章であることが必要です。

リポジトリのサイズと複雑さも考慮する必要があります。 次の種類の指示は、コントリビューターが数人だけの小規模なリポジトリでは機能しますが、大規模で多様なリポジトリの場合、Copilot の他の部分で問題が発生する可能性があります。

  • 応答を作成するときに外部リソースを参照するという要求
  • 特定のスタイルで回答するという指示
  • 常に特定の詳細レベルで応答するという要求

たとえば、次の指示では意図した結果が得られない場合があります。

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.

使われているリポジトリのカスタム命令

.github/copilot-instructions.md ファイルの指示は、ファイルを保存するとすぐに Copilot Chat によって使用できます。 完全な指示セットは、指示ファイルを含むリポジトリに関連するチャット プロンプトに自動的に追加されます。

Copilot Chat のイマーシブ ビュー (github.com/copilot) では、指示ファイルを含むリポジトリをアタッチメントとして追加して、リポジトリ カスタム指示を使う会話を開始できます。

リポジトリ カスタム指示が Copilot Chat で使われるたびに、生成される応答に対する参照として指示ファイルが追加されます。 リポジトリ カスタム指示が使われたかどうかを確認するには、[Chat] パネルのチャット応答の上部にある参照一覧を展開し、.github/copilot-instructions.md ファイルが表示されるかどうかを調べます。

展開された [References] リストのスクリーンショット。'copilot-instructions.md' ファイルが濃いオレンジ色の枠線で強調表示されています。

参照をクリックしてファイルを開くことができます。

メモ

  • It is possible for multiple types of custom instructions to apply to a conversation. Personal instructions take the highest priority, followed by repository instructions, with organization instructions prioritized last. However, all sets of relevant instructions are still combined and provided to Copilot Chat.
  • Whenever possible, you should avoid providing conflicting sets of instructions. If you are concerned about response quality, you can also choose to temporarily disable repository instructions. See GitHub Copilot のリポジトリ カスタム命令を追加する.

リポジトリのカスタム命令の有効化または無効化

チャット質問にカスタム指示を追加するかどうかを選択できます。

  1. [Chat] パネルの上部、またはイマーシブ ページの右上にある ボタンをクリックします。

  2. [Disable custom instructions] または [Enable custom instructions] をクリックします。

    メモ

    イマーシブ モードでは、カスタム命令ファイルを含むリポジトリをアタッチした場合にのみ、これらのオプションが表示されます。

選んだ内容は、変更するまで保持されます。