AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure GitHub Copilot to Ignore Sensitive Files and Repositories

Marina Domenici · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

If you expect a simple .copilotignore file in your repository root, you will be disappointed. GitHub Copilot does not read a local ignore file out of the box. Instead, GitHub splits exclusion into two tiers: centralized Content Exclusion policies managed through GitHub.com for team subscriptions, and local IDE workarounds for individual developers.

At 365Finds, we consider accidental secret exfiltration into AI prompts one of the most persistent operational risks of generative coding. Relying on developer discipline alone is a losing strategy. Here is how you configure GitHub Copilot to block sensitive credentials, along with where the guardrails hold and where they break down.


1. Native Content Exclusion (Business & Enterprise Plans Only)

GitHub provides a server-side feature called Content Exclusion. It applies across repository code completions, inline chat, Copilot Chat panels, and CLI interactions. When configured, GitHub Copilot disables suggestions inside matching files, refuses to read them in chat, and explicitly drops their contents from the context window sent to model inference endpoints.

However, there is an uncomfortable catch that many developers discover too late: Content Exclusion requires a GitHub Copilot Business or GitHub Copilot Enterprise plan. If you are paying for GitHub Copilot Individual, this feature is completely inaccessible in your settings.

Configuring Content Exclusion at the Repository Level

If you are a repository administrator within an organization:

  1. Navigate to your repository page on GitHub.com.
  2. Click Settings in the top navigation bar.
  3. In the left sidebar under Code, planning, and automation, click Copilot, then select Content exclusion.
  4. In the configuration editor, enter the file paths you want to exclude using fnmatch syntax.
  5. Click Save changes.
# Direct repository-level path rules
/config/secrets.json
/.env
/.env.*
/certs/**
/deploy/credentials.yml

Configuring Content Exclusion at the Organization or Enterprise Level

Organization owners and enterprise administrators can enforce exclusions across multiple repositories or globally across all projects under management:

  1. Go to your GitHub Organization or Enterprise settings.
  2. In the left sidebar, click Copilot, then choose Content exclusion.
  3. Define global rules prefixed with *: or target specific repository URLs:
# Global rules applying across all repositories
*:
  - "**/.env"
  - "**/.env.*"
  - "**/secrets.json"
  - "**/*.pem"
  - "**/*.key"

# Repository-specific rules within the organization
https://github.com/my-org/payment-gateway.git:
  - "/internal/keys/**"
  - "/config/production.json"

Once saved, rules propagate to connected IDEs (VS Code, Visual Studio, JetBrains IDEs) within minutes. When a developer opens an excluded file, the GitHub Copilot status bar icon shows a diagonal slash, signaling that completion and context capture are deactivated for that buffer.


2. Workarounds for GitHub Copilot Individual and Local Workspaces

If you are using GitHub Copilot Individual or working in open-source repositories where organization-wide policies cannot be enforced, you have to control the IDE environment directly.

A widespread and dangerous misconception is that adding sensitive files to .gitignore prevents GitHub Copilot from reading them. It does not. .gitignore tells Git not to commit files; it does nothing to stop the GitHub Copilot extension from reading open editor tabs or local files in the active workspace.

Disabling Copilot by File Type in VS Code

You can associate sensitive files with specific language identifiers and explicitly disable GitHub Copilot for those identifiers in .vscode/settings.json or your user configuration:

{
  "files.associations": {
    ".env*": "dotenv",
    "*.pem": "plaintext",
    "*.key": "plaintext",
    "secrets.json": "json"
  },
  "github.copilot.enable": {
    "*": true,
    "dotenv": false,
    "plaintext": false
  }
}

Disabling Copilot Entirely for an Entire Sensitive Repository

If a repository handles classified data or high-stakes keys where no AI assistance should operate, disable the extension locally at the repository root by checking a workspace setting into .vscode/settings.json:

{
  "github.copilot.enable": {
    "*": false
  }
}

This prevents GitHub Copilot from initializing for anyone opening that specific VS Code workspace.


3. The Technical Boundaries of Content Exclusion

365Finds recommends implementing Content Exclusion across every enterprise repo holding proprietary configurations, but organizations must recognize what it cannot do. GitHub’s official documentation acknowledges that Content Exclusion is not a formal filesystem security boundary.

Hardcoding secrets into source repositories and hoping exclusion rules catch them is an anti-pattern. Real credential safety requires keeping API tokens and private keys out of the workspace entirely—relying on secret vaults, environment variable injection, and automated secret scanners that reject commits before files ever reach disk.

References