Skip to main content

Finding public code that matches GitHub Copilot suggestions

Learn how to view code references when GitHub Copilot makes suggestions that matches publicly available code.

This version of this article is for Copilot in Visual Studio Code. For Copilot on other platforms, click the appropriate tab above.

Introduction

If you allow GitHub Copilot to make suggestions that match publicly available code, Copilot will display references to any similar code that is found. See Copilot code referencing.

Prerequisites

References to matching code are only generated if Copilot is configured to allow suggestions that match publicly available code. This is configured in either your personal, organization or enterprise settings.

For more information, see Managing Copilot policies as an individual subscriber, Managing policies and features for Copilot in your organization or Managing policies and features for Copilot in your enterprise.

View code references for code completion

You can find code references in one of the GitHub Copilot logs in Visual Studio Code.

  1. In Visual Studio Code, open the Output window by selecting View > Output from the menu bar.

  2. In the dropdown menu at the right of the Output window, select GitHub Copilot Log (Code References).

  3. Leave the GitHub Copilot Log (Code References) view displayed while you use GitHub Copilot in Visual Studio Code.

    When you accept a code completion suggestion that matches code in a public GitHub repository, an entry is added to the log.

    The log entry includes the following details:

    • The date and time you accepted the suggestion.
    • The name of the file in which the suggestion was added.
    • "Similar code at" followed by the location in the file where the suggestion was added.
    • An extract of the code that was added by code completion.
    • The license type for the matching code, if found, otherwise unknown.
    • The URL of the file on GitHub.com where the similar code was found.

Example log entry

2025-03-27 12:17:54.759 [info] file:///Users/monalisa/fizzbuzz.js Similar code at  [Ln 2, Col 8] let i = 1; i <= 100; i++) {  let output = '';  if (i % 3 === 0) {  output += 'Fizz';...
2025-03-27 12:17:54.759 [info] License: unknown, URL: https://github.com/octo-org/octo-repo/blob/8563f3b1d4f33952b22212b86e745539d1567ed1/examples/fizzBuzz.js
2025-03-27 12:17:54.759 [info] License: MIT, URL: https://github.com/octo-org/monalisa/blob/7e974691f4c8e6bc55f9b50688f05d746d1bc52b/exercises/2/fizz-buzz.js

Verifying the code referencing functionality

You can verify that code referencing is working by prompting Copilot to add some commonly used code and checking the output in the log.

  1. Create a file called fizz-buzz.js and open it in the editor.

  2. Display the log as described in the previous section.

  3. In the editor, type:

    function fizzBuzz()
    

    With a space after the closing parenthesis.

    GitHub Copilot should suggest code to complete the function. Typically the suggestion will be a common implementation of the fizz buzz algorithm that will match publicly available code on the GitHub website.

  4. To accept the suggestion, press Tab.

  5. Check whether any entries for similar code have been added to the log.

View code references for Copilot Chat

If a response in Copilot Chat includes matching code, this is indicated at the end of the response by the following text:

Similar code found with n license types - View matches

  1. Click View matches to display details of the matched code in a new editor tab.

    For each example of matching code, the editor displays:

    • The license type for the matching code, if known.
    • The URL of the file on GitHub.com where the matching code was found.
    • A code snippet showing the matching code.
  2. In the editor, Ctrl+click (Windows/Linux) or Command+click (Mac) a URL to view the full file on GitHub.com.

Further reading