AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Exclude Files and Repositories from GitHub Copilot Code Completion

葉景棠 · 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

You can stop GitHub Copilot from reading or autocompleting sensitive code, but only if you hold the right license and configure exclusions in the right place. GitHub provides a native Content Exclusion engine that blocks Copilot from indexing files, suggesting completions inside them, or sending their contents into prompt contexts.

However, there is an immediate catch that frustrates individual developers: native, server-enforced content exclusion is strictly reserved for Copilot Business and Copilot Enterprise organizations. If you are on Copilot Individual, you are forced to manage exclusions locally inside your editor.

At 365Finds, we have audited how teams implement these policies. Here is the operational playbook for repository administrators, organization owners, and solo developers, along with where this safeguard falls short.


1. Excluding Files in a Specific Repository (Admin)

If your repository belongs to an organization with Copilot Business or Enterprise, repository administrators can set exclusion rules directly in the repository settings.

Step-by-Step Configuration:

  1. Navigate to the main page of your repository on GitHub.
  2. Click Settings in the top navigation bar.
  3. In the left sidebar, under Code, planning, and automation, select Copilot, then click Content exclusion.
  4. In the text area labeled Paths to exclude in this repository, enter each exclusion pattern on a new line.
  5. Click Save (or Save changes).

Path Syntax and fnmatch Pattern Rules:

GitHub uses fnmatch pattern matching (case-insensitive). Every path relative to the root of the repository must begin with a forward slash (/).

# Exclude a specific sensitive configuration file
/config/production.json

# Exclude an entire directory and all subdirectories
/certs/**
/internal-tools/**

# Exclude specific file types anywhere in the repository
*.pem
*.key
*.env*

# Exclude a specific file by name anywhere in the repo
**/credentials.xml

Note on inheritance: If your parent organization or enterprise has already declared global exclusions, those rules will appear at the top in gray boxes. You cannot override, weaken, or delete higher-level exclusions from inside a single repository.


2. Excluding Entire Repositories or Multi-Repo Paths (Org & Enterprise)

Managing exclusion file by file across dozens of microservices is unsustainable. Organization owners and Enterprise administrators can enforce global bans across multiple repositories simultaneously.

Where to Configure:

Configuration Format:

In the organization settings box, reference the repository name followed by the targeted path list:

# Completely exclude an entire repository from GitHub Copilot
owner/internal-proprietary-core:
  - "/**/*"

# Exclude sensitive folders in a specific repository
owner/payment-gateway:
  - "/vault/**"
  - "/src/legacy-crypto/**"

# Exclude files across another repository
owner/auth-service:
  - "/secrets/*"

Applying "/**/*" tells the GitHub Copilot backend that the designated repository is a black box. No inline suggestions will ever trigger inside it, and no code from it will be transmitted to Copilot servers to assist other repositories.


3. What Happens in the Editor (And the Propagation Delay)

Once a file is excluded, the behavior across supported IDEs (Visual Studio Code, JetBrains IDEs, Visual Studio, and Xcode) changes immediately:

  1. Suppressed Completions: The moment an engineer opens an excluded file, GitHub Copilot's status bar icon indicates that suggestions are disabled (often displaying a slash or inactive status). Ghost text autocompletions will not appear.
  2. Context Window Shielding: The contents of that open file will not be included in the context payload sent to Copilot when writing code in neighboring open tabs.
  3. Chat and Code Review Block: Copilot Chat will refuse to summarize, analyze, or generate tests using the content of excluded files.

The Propagation Reality

Do not expect instant synchronization across your team's machines. Policy updates on GitHub.com can take up to 30 minutes to propagate through GitHub's policy servers to active IDE client sessions.

If an engineer needs the rule applied immediately, they must reload their editor window (in VS Code: Ctrl+Shift+P / Cmd+Shift+P ➔ Developer: Reload Window) or sign out and back into their GitHub account in the editor.


4. The Individual Plan Dilemma: Client-Side Workarounds

GitHub does not offer the web-based Content Exclusion dashboard to Copilot Individual accounts. 365Finds considers this a glaring gap in GitHub's safety tiering. Solo developers and contractors handling proprietary client code need protection just as much as enterprises.

If you are on Copilot Individual, you have two local mitigation options inside VS Code:

Option A: Disable Copilot for Specific Languages and File Types

You can configure VS Code's settings.json (or .vscode/settings.json within your workspace) to turn off Copilot for custom file associations:

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

Option B: Disable Copilot Completely for a Workspace

When working on a sensitive repository where you want zero Copilot activity:

  1. Open the project root in VS Code.
  2. Open the Extensions sidebar (Ctrl+Shift+X or Cmd+Shift+X).
  3. Find GitHub Copilot, click the gear icon, and select Disable (Workspace).
  4. VS Code creates a local workspace configuration that leaves Copilot running for your personal open-source projects while silencing it completely inside that client directory.

5. 365Finds Commercial Judgment: Guardrail vs. Security Perimeter

365Finds recommends implementing Content Exclusion across all corporate repositories containing proprietary trade secrets or sensitive schema configurations. The friction for developers is zero, and the policy enforcement is centralized.

However, we must issue a blunt warning: Content exclusion is a policy guardrail, not an encryption boundary or a security perimeter.

Many engineering leads make the dangerous mistake of assuming that adding .env or /keys/ to Copilot Content Exclusion makes it safe to keep raw credentials in Git. It does not:

Our firm stance at 365Finds is that Content Exclusion should always be the second layer of defense, never the first. Real secrets belong in a dedicated secret store (such as HashiCorp Vault, Doppler, or AWS Secrets Manager) and in .gitignore. Use Copilot Content Exclusion to protect proprietary algorithms, competitive intellectual property, and internal frameworks from model indexing.

References