How to Restrict GitHub Copilot by File: Supported Exclusions and Limits
🔍 WiseChecker

How to Restrict GitHub Copilot by File: Supported Exclusions and Limits

To stop Copilot using particular files, choose the control that matches your goal. Suppressing inline suggestions, reducing noisy search results and enforcing a content-exclusion policy are different tasks. A repository file named .github/copilot.yml with include and exclude keys is not the documented way to impose these restrictions.

ADVERTISEMENT

Choose a Supported Control

  • Stop suggestions in a language: use the editor’s Copilot completion settings. This is not a confidentiality rule.
  • Keep generated files out of search/index context: use supported workspace exclusion settings. An agent with file or terminal access may still obtain content by other routes.
  • Exclude paths from supported Copilot features: a repository administrator, organization owner or enterprise owner can configure content exclusions for an eligible Business/Enterprise organization.

GitHub’s content-exclusion reference explains the scope. In supported experiences, excluded files do not supply inline suggestions, chat context or code-review content. This does not create a universal file-access firewall.

Configure Repository Content Exclusions

  1. On GitHub, open the repository’s Settings → Copilot → Content exclusion.
  2. Review inherited restrictions before adding rules. A repository administrator cannot edit parent-organization exclusions from this page.
  3. Under Paths to exclude in this repository, enter a YAML list of paths. Adapt the following example to real, reviewed paths; do not paste it unchanged as a security policy.
- "/generated/**"
- "/config/private.json"
- "*.key"

The documented patterns use fnmatch notation and are case-insensitive. Comments can begin with #. Do not import the former article’s conflicting include/exclude precedence rules: this settings field is a list of exclusions, not a repository-wide allowlist file. See GitHub’s configuration examples.

Apply the change and test before rollout. Existing IDE sessions can take up to 30 minutes to pick up a policy; in VS Code, Developer: Reload Window reloads the settings sooner.

ADVERTISEMENT

Use Editor Preferences for Noise Reduction

If you only want inline completions in selected languages, VS Code’s documented github.copilot.enable setting accepts language IDs. For example:

"github.copilot.enable": {
  "*": false,
  "typescript": true,
  "typescriptreact": true
}

Merge this into existing settings rather than replacing the file. This chooses languages, not folders: it does not mean “only files under src,” and it does not stop Chat or agents reading other files. Review the IDE configuration guide.

For search relevance, .gitignore, files.exclude and search.exclude have different scopes. VS Code’s workspace-context guide documents them; an open or selected gitignored file can still enter context. These are useful noise controls, not proof that a secret can never be transmitted.

Verify the Policy and Its Limits

Use synthetic, non-sensitive test files. Confirm suggestions work in an allowed file and are suppressed in an excluded one; then use the official supported-chat test and check the referenced context. Record the client version, account and mode. Testing with a real API key is unnecessary and unsafe.

GitHub currently documents that content exclusion does not cover Edit and Agent modes in VS Code and other editors, and lists limitations for symbolic links, remote filesystems and indirectly supplied semantic information. Do not extend a successful inline-completion test to those modes.

CLI documentation is not consistent on exclusion support at the time of this review. If CLI enforcement matters, obtain confirmation for your deployed version before allowing confidential files in its accessible environment. A policy test in VS Code cannot establish CLI protection.

Keep credentials in an approved secret store, restrict actual filesystem/network permissions where needed, and do not rely on a natural-language instruction as access control. If an exposed credential is discovered, rotate it and follow your incident process; an exclusion rule cannot undo past disclosure.

Official documentation checked: October 14, 2026.

ADVERTISEMENT