Skip to main content

GitHub Copilotからコンテンツを除外する

          Copilotが特定のコンテンツにアクセスできないようにする方法について説明します。

この機能を使用できるユーザーについて

Repository administrators, organization owners, and enterprise owners can manage content exclusion settings. People with the "Maintain" role for a repository can view, but not edit, content exclusion settings for that repository.

Copilot ビジネス サービス または Copilot Enterprise プランを所有する organization。

リポジトリのコンテンツ除外の構成

リポジトリ設定を使用して、 GitHub Copilot が無視する必要があるリポジトリ内のコンテンツを指定できます。

メモ

          GitHub Copilot CLI、 Copilotクラウドエージェント、および IDE の Copilot Chat のエージェント モードでは、コンテンツの除外はサポートされていません。 これらの Copilot 機能の詳細については、「 [AUTOTITLE](/copilot/concepts/agents/about-copilot-cli)、 [AUTOTITLE](/copilot/concepts/agents/cloud-agent/about-cloud-agent)、 [AUTOTITLE](/copilot/how-tos/chat-with-copilot/chat-in-ide)」を参照してください。
  1. GitHub で、リポジトリのメイン ページに移動します。

  2. リポジトリ名の下にある [Settings] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。

    タブを示すリポジトリ ヘッダーのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で強調表示されています。

  3. サイドバーの「コード&オートメーション」セクションで、「 Copilot 」をクリックし、「 コンテンツの除外」をクリックします。

    リポジトリが親 organization から、または同じ Enterprise 内の organization から除外を継承している場合、ページの上部に、これらの除外の詳細を含む灰色のボックスが 1 つ以上表示されます。 これらの設定は編集できません。

  4. [このリポジトリで除外するパス] の下のボックスに、 Copilot を除外するファイルへのパスを入力します。

    各パスを別々の行にして、形式 - "/PATH/TO/DIRECTORY/OR/FILE" を使用します。 行頭を # にすることで、コメントを追加できます。

    ヒント

    fnmatch パターン マッチング表記を使用して、ファイル パスを指定できます。 パターンでは大文字と小文字が区別されません。 ruby-doc.org ドキュメントの「ファイル」を参照してください。

リポジトリ設定で指定されたパスの例

YAML
- "/src/some-dir/kernel.rs"

Ignore the /src/some-dir/kernel.rs file in this repository.

- "secrets.json"

Ignore files called secrets.json anywhere in this repository.

- "secret*"

Ignore all files whose names begin with secret anywhere in this repository.

- "*.cfg"

Ignore files whose names end with .cfg anywhere in this repository.

- "/scripts/**"

Ignore all files in or below the /scripts directory of this repository.

# Ignore the `/src/some-dir/kernel.rs` file in this repository.
- "/src/some-dir/kernel.rs"

# Ignore files called `secrets.json` anywhere in this repository.
- "secrets.json"

# Ignore all files whose names begin with `secret` anywhere in this repository.
- "secret*"

# Ignore files whose names end with `.cfg` anywhere in this repository.
- "*.cfg"

# Ignore all files in or below the `/scripts` directory of this repository.
- "/scripts/**"

Organization のコンテンツ除外の構成

組織の設定を使用して、 GitHub Copilot が無視する必要があるファイルを指定できます。 ファイルは、Git リポジトリ内、または Git の管理下にないファイル システム上の任意の場所に配置できます。

  1. GitHub の右上隅にあるプロフィール画像をクリックしてから、[ Your organizations] をクリックします。

  2. 組織をクリックして選択します。

  3. Organization 名の下で、[ Settings] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。

    組織のプロファイルのタブのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で囲まれています。

  4. 左側のサイドバーで、[ Copilot ] をクリックし、[ コンテンツの除外] をクリックします。

  5. [除外するリポジトリとパス] の下のボックスに、 Copilot を除外するファイルの詳細を入力します。

    任意の場所 (Git リポジトリ内または他の場所) にあるファイルを除外するには、"*": を入力し、その後に除外するファイル (複数可) へのパスを入力します。 複数のファイル パス パターンを指定する場合は、各パターンを個別の行に一覧表示します。

           Copilotから Git リポジトリ内のファイルを除外するには、リポジトリへの参照を 1 行に入力し、その後にリポジトリ内の場所へのパスを入力し、各パスを個別の行に配置します。 次の形式を使用して、`REPOSITORY-REFERENCE` を、除外するファイルを含むリポジトリへの参照に置き換えます。
    
    REPOSITORY-REFERENCE:
      - "/PATH/TO/DIRECTORY/OR/FILE"
      - "/PATH/TO/DIRECTORY/OR/FILE"
      - ...
    

    リポジトリは、さまざまなプロトコルを使用して参照できます。 REPOSITORY-REFERENCEには次のいずれかの構文を使用できます。Copilotは、リポジトリのローカルでの複製方法に関係なく、これらの構文と一致します。

    http[s]://host.xz[:port]/path/to/repo.git/
    
    git://host.xz[:port]/path/to/repo.git/
    
    [user@]host.xz:path/to/repo.git/
    
    ssh://[user@]host.xz[:port]/path/to/repo.git/
    

    リポジトリに対して無視するパスの計算では、user@:port 部分と REPOSITORY-REFERENCE 部分は無視されます。

    Azure DevOpsの場合は、REPOSITORY-REFERENCEを指定するときに新しい (dev.azure.com) または古い (visualstudio.com) ホスト形式を使用できます。Copilot は、リポジトリをローカルに複製するために使用されたホストに関係なく、それらに一致します。

    ヒント

    fnmatch パターン マッチング表記を使用して、ファイル パスを指定できます。 パターンでは大文字と小文字が区別されません。 ruby-doc.org ドキュメントの「ファイル」を参照してください。

Organization 設定のリポジトリとパスの例

YAML
"*":
  - "**/.env"

Ignore all .env files from all file system roots (Git and non-Git). For example, this excludes REPOSITORY-PATH/.env and also /.env. This could also have been written on a single line as:

"*": ["**/.env"]

octo-repo:

In the octo-repo repository in this organization:

  - "/src/some-dir/kernel.rs"

Ignore the /src/some-dir/kernel.rs file.

https://github.com/primer/react.git:

In the primer/react repository on GitHub:

  - "secrets.json"

Ignore files called secrets.json anywhere in this repository.

  - "/src/**/temp.rb"

Ignore files called temp.rb in or below the /src directory.

git@github.com:*/copilot:

In the copilot repository of any GitHub organization:

  - "/__tests__/**"

Ignore any files in or below the /__tests__ directory.

  - "/scripts/*"

Ignore any files in the /scripts directory.

git@gitlab.com:gitlab-org/gitlab-runner.git:

In the gitlab-org/gitlab-runner repository on GitLab:

  - "/main_test.go"

Ignore the /main_test.go file.

  - "{server,session}*"

Ignore any files with names beginning with server or session anywhere in this repository.

  - "*.m[dk]"

Ignore any files with names ending with .md or .mk anywhere in this repository.

  - "**/package?/*"

Ignore files directly within directories such as packages or packaged anywhere in this repository.

  - "**/security/**"

Ignore files in or below any security directories, anywhere in this repository.

# Ignore all `.env` files from all file system roots (Git and non-Git).
# For example, this excludes `REPOSITORY-PATH/.env` and also `/.env`.
# This could also have been written on a single line as:
#
# "*": ["**/.env"]
"*":
  - "**/.env"

# In the `octo-repo` repository in this organization:
octo-repo:
  # Ignore the `/src/some-dir/kernel.rs` file.
  - "/src/some-dir/kernel.rs"

# In the `primer/react` repository on GitHub:
https://github.com/primer/react.git:
  # Ignore files called `secrets.json` anywhere in this repository.
  - "secrets.json"
  # Ignore files called `temp.rb` in or below the `/src` directory.
  - "/src/**/temp.rb"

# In the `copilot` repository of any GitHub organization:
git@github.com:*/copilot:
  # Ignore any files in or below the `/__tests__` directory.
  - "/__tests__/**"
  # Ignore any files in the `/scripts` directory.
  - "/scripts/*"

# In the `gitlab-org/gitlab-runner` repository on GitLab:
git@gitlab.com:gitlab-org/gitlab-runner.git:
  # Ignore the `/main_test.go` file.
  - "/main_test.go"
  # Ignore any files with names beginning with `server` or `session` anywhere in this repository.
  - "{server,session}*"
  # Ignore any files with names ending with `.md` or `.mk` anywhere in this repository.
  - "*.m[dk]"
  # Ignore files directly within directories such as `packages` or `packaged` anywhere in this repository.
  - "**/package?/*"
  # Ignore files in or below any `security` directories, anywhere in this repository.
  - "**/security/**"

Enterprise のコンテンツ除外の構成

エンタープライズ所有者は、エンタープライズ設定を使用して、 GitHub Copilot が無視する必要があるファイルを指定できます。 ファイルは、Git リポジトリ内、または Git の管理下にないファイル システム上の任意の場所に配置できます。

  1. 企業ページに移動してください。 たとえば、GitHub.com の [Enterprise] ページから。
  2. ページの上部にある AI コントロールをクリックします。
  3. サイドバーで Copilot をクリックします。
  4.        <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-circle-slash" aria-label="circle-slash" role="img"><path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM3.965 13.096a6.5 6.5 0 0 0 9.131-9.131ZM1.5 8a6.474 6.474 0 0 0 1.404 4.035l9.131-9.131A6.499 6.499 0 0 0 1.5 8Z"></path></svg>
           **コンテンツを除外** をクリックします。
    
  5. パスを使用して、除外するコンテンツを指定します。 前のセクション「Organization のコンテンツ除外の構成」をご覧ください。

メモ

エンタープライズ レベルでコンテンツの除外を設定することと組織レベルで設定する主な違いは、エンタープライズ レベルで設定されたルールは、企業内のすべての Copilot ユーザーに適用されるのに対し、組織の所有者によって設定されたルールは、その組織によって Copilot シートが割り当てられているユーザーにのみ適用される点です。

コンテンツ除外の変更をテストする

IDE を使用して、コンテンツ除外の変更が想定どおりに動作していることを確認できます。

IDE にコンテンツ除外の変更を伝達する

コンテンツの除外を追加または変更し、設定が既に読み込まれている IDE で有効になるまでに最大で 30 分かかることがあります。 待機しない場合は、次の手順を使用して、コンテンツの除外設定を手動で再読み込みできます。

  •         **JetBrains IDE とVisual Studioの場合**は、アプリケーションを閉じて再度開いて、コンテンツ除外設定を再読み込みします。
    
  •         **
            Visual Studio Codeの場合**は、次の手順に従ってコンテンツの除外設定を再読み込みします。
    
    1. コマンドパレットにアクセスします。 たとえば、次のようになります。 Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux)。
    2. 次のコマンドを入力します: reload
    3.      **[開発者: ウィンドウの再読み込み]** を選択します。
      
  •         **Vim/Neovim**、ファイルを開くたびに GitHub からコンテンツの除外が自動的にフェッチされます。
    

コンテンツの除外をテストする

構成したコンテンツ除外が想定どおりに動作していることを確認できます。

  1. まず、コンテンツ除外の対象ではないファイルで、コンテンツ除外が機能していることを確認します。 これを行うには:
    • IDE で、コンテンツ除外の対象ではないファイルを開きます。
    • 通常、インライン提案が生成されるような編集を行ってください。 提案が提供されるはずです。
  2. 除外される必要があるファイルを開き、同じ編集を行います。 提案は提供されません。
  3.        Copilot Chatのコンテンツ除外をテストするには:
    
    • IDE で、 Copilot Chat パネルを開きます。

    • 除外される必要があるファイルを開き、エディターで開いている他のファイルを閉じます。

    • 開いているファイルがコンテキスト ファイルとしてプロンプトに添付されることを確認します。

    • プロンプト explain this file を入力します。

      ファイルが除外されている場合、 Copilot Chat はそのファイルを使用して応答を生成できなくなります。 ファイルは、 Copilotの応答の参照として一覧表示されません。

REST API を使用してコンテンツの除外を管理する

組織の所有者とエンタープライズ所有者は、 GitHub REST API を使用してプログラムでコンテンツの除外を管理することもできます。

詳しくは、「Copilot コンテンツの除外管理のための REST API エンドポイント」をご覧ください。

参考資料

  •         [AUTOTITLE](/copilot/concepts/content-exclusion-for-github-copilot)
    
  •         [AUTOTITLE](/copilot/managing-copilot/managing-github-copilot-in-your-organization/managing-access-to-github-copilot-in-your-organization/reviewing-changes-to-content-exclusions-for-github-copilot)
    
  •         [ Microsoft Learn ドキュメントの Visual Studio](https://learn.microsoft.com/en-us/visualstudio/ide/visual-studio-github-copilot-admin?view=vs-2022#configure-content-exclusion) のコンテンツ除外の構成