AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Exclude Files and Repositories from GitHub Copilot Code Completion

Ana Lázaro Touza · 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 are managing sensitive proprietary algorithms, private certificates, or compliance-restricted repositories, you do not want an AI assistant reading those buffers into prompt context. 365Finds tested and evaluated the administrative and local methods to block GitHub Copilot, and the short answer is straightforward: the official mechanism is Content Exclusion.

The critical commercial reality is that GitHub locks native Content Exclusion behind GitHub Copilot Business ($19 per user/month) and GitHub Copilot Enterprise ($39 per user/month). If you run GitHub Copilot Individual ($10 per month), GitHub gives you no native web repository settings to block file paths. You have to rely on local editor workarounds.

At 365Finds, our stance is clear: Content Exclusion is a valuable compliance guardrail, but it is not a cryptographic vault. You should use it systematically across your organization, while understanding exactly what it does, how to configure it at every level, and where its protective boundaries end.


What Happens When You Exclude Content

When a file or repository matches an active exclusion rule:

In editors like Visual Studio Code, the GitHub Copilot status bar icon shows a distinct diagonal slash when an excluded file is open. Hovering over the icon displays a tooltip confirming that completions are disabled by content exclusion policies.


Method 1: Exclude Paths or Entire Repositories at the Repository Level

If you are a repository administrator (and your organization has a Copilot Business or Enterprise subscription), you can configure exclusions directly inside the repository.

Step-by-Step Configuration

  1. Open your repository on GitHub.com.
  2. Click Settings in the top navigation tab.
  3. In the left sidebar under Code, planning, and automation, click Copilot, then click Content exclusion.
  4. In the Paths to exclude in this repository text box, enter your path patterns using YAML list syntax.
  5. Click Save.

Path Syntax and Examples

Each rule must be enclosed in quotation marks and preceded by a hyphen (-). Rules use fnmatch wildcard syntax and are case-insensitive. You can prefix lines with # for comments.

# Exclude the entire repository from Copilot completion
- "/**"

# Exclude sensitive directories
- "/secrets/**"
- "/internal/crypto/**"

# Exclude specific files anywhere in the repo
- "*.env"
- "secrets.json"
- "credentials.yml"

# Exclude specific file types
- "*.pem"
- "*.key"

To shut down GitHub Copilot across an entire repository without disabling the seat for the developer, adding - "/**" or - "*" at the repository root is the cleanest, fastest method.


Method 2: Enforce Exclusions Across an Entire Organization or Enterprise

Managing exclusions repo by repo is fragile. Organization owners and enterprise administrators should set blanket policies centrally.

Organization-Level Setup

  1. Go to your organization page on GitHub.com and click Settings.
  2. In the left sidebar, select Copilot > Content exclusion.
  3. Under Repositories and paths to exclude, define your rules.

At the organization level, you can target specific repositories using their clone URL, or apply global file rules across every repository in the organization using the *: prefix:

# Block an entire sensitive repository by repository reference
https://github.com/your-org/payments-core.git:
  - "**"

# Block specific subdirectories inside another repository
git@github.com:your-org/analytics-service.git:
  - "/config/production/**"
  - "/keys/**"

# Universal block across all organization repositories (Git and non-Git)
*:
  - "*.env"
  - "*.pem"
  - "id_rsa*"
  - "/deploy/credentials.json"

Enterprise Inheritance

If your enterprise administrator configures rules under Enterprise AI controls > Copilot > Content exclusion, those rules become mandatory baselines. Organization and repository settings display enterprise-enforced paths in gray, locked boxes. Lower-level admins cannot remove or override them.


Propagation Timing: Don't Panic When It Takes Minutes

Changes saved on GitHub.com do not apply immediately to active IDE sessions. GitHub caches policies locally in editor extensions.

Once reloaded, opening any excluded file will immediately trigger the crossed-out Copilot icon in the status bar.


The Copilot Individual Workaround (Local VS Code Settings)

What if your company uses GitHub Copilot Individual ($10/user) where Content Exclusion is unavailable?

There is no native .copilotignore file supported out-of-the-box by GitHub. However, you can prevent inline completions locally in VS Code by disabling the extension for sensitive language types or filenames in .vscode/settings.json:

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

365Finds does not recommend this as an enterprise security policy. Any developer can delete their local .vscode folder or change language associations back to Python or TypeScript, instantly reactivating Copilot. Treat this purely as personal friction against accidental leakage, not organizational governance.


The Boundaries: What Content Exclusion Does NOT Protect

365Finds advises engineering teams to maintain realistic expectations regarding Copilot Content Exclusion:

Protection DimensionContent Exclusion CapabilityEngineering Reality
Inline suggestions in fileBlocked completelyEffective guardrail against accidental autocompletes
Neighboring file prompt injectionExcluded files are omitted from prompt contextEffective; prevents open tabs from leaking code
Copilot Chat contextBlocked from reading excluded pathsWorks for official @workspace and chat tools
Type and symbol inferencePartial leak possibleIf unexcluded files import exported types, Copilot infers shapes
Hardcoded secrets protectionNOT a security boundarySecrets must live in a vault, never in the repository
Non-GitHub AI tools & CLI scriptsIneffectiveThird-party MCP tools and external scripts ignore GitHub policies

If a database password or private signing key is sitting in an excluded file in cleartext, that credential is fundamentally unmanaged. Content Exclusion keeps the buffer out of GitHub Copilot's prompt window, but it does not sanitize your git history or protect against malicious extensions.

365Finds recommends using Content Exclusion as layer two of a three-layer defense: automated secret scanning (like Gitleaks or GitHub Secret Scanning) at commit time, centralized credential vaults for production keys, and repository-wide - "/**" exclusions on proprietary or highly regulated codebases.

References