AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Exclude Sensitive Files and Repositories from GitHub Copilot Context

William Sinykin · 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

Developers looking for a .copilotignore file in their repository root will quickly discover a frustrating reality: GitHub Copilot does not have a native, in-repo ignore file. Putting a .copilotignore next to your .gitignore does nothing out of the box.

GitHub manages file exclusions server-side through a feature called Content Exclusion, gated behind GitHub Copilot Business and Enterprise subscriptions. If you need to stop GitHub Copilot from slurping proprietary business logic, .env files, or entire private repositories into its inference window, you have to configure it either through organization policies, repository settings, or local editor overrides.

At 365Finds, we believe GitHub's decision to withhold native file-based exclusions from individual developers and lock centralized exclusion behind higher-tier enterprise seats is an unnecessary operational hurdle. Here is exactly how content exclusion works, how to configure it across repositories, and where its actual protection boundaries end.


1. The Myth of .copilotignore

Many engineering teams assume GitHub Copilot mirrors Git conventions with an ignore file committed to version control. It does not.

There are unofficial third-party VS Code extensions (such as copilotignore-vscode) that parse a local .copilotignore and attempt to toggle the Copilot extension status whenever an active editor tab matches an ignored pattern. At 365Finds, we explicitly advise against relying on these community extensions for enterprise security. They operate strictly on the client side, depend on client focus events, break during background tool indexing, and cannot be centrally audited or enforced across a distributed development team.

If you are on an official GitHub Copilot Business or Enterprise tier, you must use GitHub's native Content Exclusion.


2. Exclude Files at the Repository Level

Repository administrators can exclude specific files, directories, or file extensions directly from the repository's settings on GitHub.

Step-by-Step Configuration:

  1. Navigate to your repository on GitHub.
  2. Select Settings in the top navigation bar.
  3. In the left sidebar, navigate to Code, planning, and automation > Copilot > Content exclusion.
  4. In the Paths to exclude in this repository editor, enter the target paths using fnmatch glob syntax. Each path must be formatted as a YAML list item (- "path").
  5. Click Save changes.
# Block specific secret files
- ".env"
- ".env.*"
- "config/master.key"

# Block an entire directory of proprietary algorithms
- "src/proprietary/**"
- "internal/core-engine/**"

# Block specific file extensions across all subdirectories
- "**/*.pem"
- "**/*.key"
- "**/*.cert"

What Happens Once Saved:

Note: Changes can take up to 30 minutes to propagate to active IDE instances. Restarting the editor or reloading the Copilot language server accelerates the sync.


3. Exclude Files and Entire Repositories at the Organization Level

For engineering leaders managing dozens or hundreds of microservices, configuring exclusions repo-by-repo is impractical. Organization and Enterprise administrators can configure global exclusion schemas that cascade down to all managed repositories.

Step-by-Step Organization Setup:

  1. In the top right corner of GitHub, click your profile picture and select Your organizations.
  2. Select your organization and click Settings.
  3. In the left sidebar, click Copilot > Content exclusion.
  4. Enter your exclusion rules in the YAML configuration box.

Exclude Across All Repositories:

Use the wildcard "*" repository key to apply file path blocks across every repository owned by the organization:

"*":
  - "**/.env"
  - "**/.env.*"
  - "**/secrets/**"
  - "**/*.pem"
  - "**/*.pfx"

Exclude an Entire Private Repository:

To completely blind GitHub Copilot to a specific private repository, target the repository's HTTPS URL and block all files using "**":

"https://github.com/your-org/highly-confidential-algo":
  - "**"

When an entire repository is matched by "**", Copilot shuts down completely within that workspace. Any exclusions defined at the enterprise or organization level will appear as grayed-out, read-only entries in the repository-level settings, preventing individual repository admins from overriding them.


4. Local Workarounds for Copilot Individual Subscribers

GitHub does not provide the Content Exclusion dashboard for Copilot Individual subscribers ($10/month). If you are a solo contractor or small team without an organization plan, your options are limited to editor-level language toggles.

In Visual Studio Code, open your settings.json (either User or Workspace level) and disable Copilot for specific languages or file associations:

{
  "files.associations": {
    ".env*": "dotenv",
    "*.secret": "plaintext"
  },
  "github.copilot.enable": {
    "*": true,
    "dotenv": false,
    "plaintext": false,
    "yaml": false
  }
}

This prevents inline completions when a file with that language identifier is focused. However, 365Finds emphasizes: this does not provide cryptographic or context isolation. If Copilot Chat or agentic indexing scans the workspace directory, language toggles in settings.json do not guarantee workspace-wide context exclusion.


5. Security Realities: What Content Exclusion Does Not Do

365Finds cautions every engineering organization: Content exclusion is a prompting filter, not an access control boundary.

  1. Secrets Do Not Belong in Code: If an API secret or database credential is committed to git, adding it to Content Exclusion does not secure it. It only asks Copilot not to read it. Secrets belong in credential vaults (such as HashiCorp Vault, AWS Secrets Manager, or Doppler) or environment injection pipelines, not plaintext files.
  2. Indirect Semantic Leakage: If secrets_handler.py is excluded, but payment_service.py imports functions, classes, and parameter names from it, Copilot still reads payment_service.py. It can infer function signatures, business architecture, and parameter schemas from downstream references.
  3. Symlinks and External Mounts: GitHub's documentation explicitly notes that Content Exclusion does not apply to symbolic links or files located on remote network filesystems.

Enterprise exclusion policies prevent casual leakage of proprietary modules into AI prompt contexts, but genuine IP and credential security requires strict repository permissions, automated secret scanners, and zero-trust credential architectures.

References