October 7th, 2024

Configure GitHub Copilot Access via Content Exclusion

Alexandra Kemper
Product Manager

Have you ever wanted greater control over the sensitive content AI-powered tools can access in your repositories? You can now customize Copilot’s access to your files with the newly announced GitHub Copilot Content Exclusion in both Visual Studio and Visual Studio Code. Through this new process you can configure Copilot to ignore certain files in your repository – such as sensitive files or information – when generating responses.  

Once content has been excluded from Copilot:  

  • Code completion will not be available in the affected files. 
  • The content in affected files will not inform code completion suggestions in other files. 
  • The content in affected files will not inform GitHub Copilot Chat’s responses. 

GitHub Copilot’s granular control over content exclusion gives you the flexibility to enact company-wide security policies in your organization and prevent unauthorized access to sensitive information so developers can still benefit from Copilot across every step of the developer workflow. 

For further details, limitations, and the latest information, refer to the content exclusion documentation. 

Example: Excluding Content in the C++ STL 

For example, imagine you are customizing Microsoft’s implementation of the C++ Standard Library. You rewrite the validation logic and add your own tools, which are specific for your codebase and include proprietary information. You can exclude these changes from Copilot by excluding the entire tools folder:   

A screenshot of a file that includes the line "/tools/**/*" and says "paths to exclude in this repository" at the top

When you open any of the excluded files in your IDE, you can now determine that Copilot is disabled from the GitHub Copilot indicator in your status bar. For example, when opening tools/validate/validate.cpp in VS Code and hovering over the GitHub icon, you’ll notice that the file has been excluded:   

Image of a mouse hovering over the Copilot Icon in the status bar of VS Code. The icon has a line over it and text that appears when it hovers states "Your repository "STL" has disabled copilot for this file"

Now, when you make a request to Copilot, any excluded content will be ignored. This applies to both in line code completions and GitHub Copilot Chat, and is indicated by a note at the end of each response:  

Screenshot of a code completion in VS Code. It has been cropped to show that the bottom of the inline suggestion shows the text "note: some files were excluded from the context due to content exclusion rules"

A screenshot of the copilot chat response in VS Code. It shows that at the bottom of the reponse there is the same note as for inline suggestions whenever a file is referenced that has been excluded.

For further information and the latest details, please reference the content exclusion documentation. 

Excluding Files Not in Git? 

A new addition, currently in public beta, is that content exclusion is not only limited to files that are tracked through Git. Any exclusions added apply to any non-git files that are a part of your repository as well. For example, as a game developer, indicating a wildcard scope like “*.exe” from the previous section would automatically apply to any files in your repository, even if these .exe files are tracked through Azure DevOps, Perforce, or stored locally.   

What do you think?  

Download the GitHub Copilot Extension for Visual Studio Code  today to try content exclusion and let us know what you think. Note that the GitHub Copilot extension comes bundled with the GitHub Copilot Chat extension.  

If you have any questions, comments, or feedback please reach out via the comments below, per email at  visualcpp@microsoft.com, or through our team on X/Twitter at  @VisualC. If you experience any issues, please report them in our GitHub repo.  

Author

Alexandra Kemper
Product Manager

0 comments