You can ask Copilot Chat specific questions about your project or general software questions. You can also ask Copilot Chat to write code, fix errors, write tests, and document code.
Use the tabs above to select the environment where you are using Copilot Chat.
Some of the following example prompts use chat participants (preceded by @), slash commands (preceded by /), or chat variables (preceded by #). For more information on keywords in prompts, see Asking GitHub Copilot questions in your IDE.
You can ask Copilot to write code for you. For example:
write a function to sum all numbers in a list
add error handling to this function
@workspace add form validation, similar to the newsletter page
When Copilot returns a code block, the response includes options to copy the code, or to insert the code at your cursor, into a new file, or into the terminal.
You can ask Copilot about security alerts in repositories in your organization from GitHub Advanced Security features (code scanning, secret scanning, and Dependabot alerts). For example:
How would I fix this alert?
How many alerts do I have on this pull request?
Which line of code is this code scanning alert referencing?
What library is affected by this Dependabot alert?
Use the /new slash command to set up a new project. For example:
/new react app with typescript
/new python django web application
/new node.js express server
Copilot will suggest a directory structure and provide a button to create the suggested files and contents. To preview a suggested file, select the file name in the suggested directory structure.
Use the /newNotebook slash command to set up a new Jupyter notebook. For example:
/newNotebook retrieve the titanic dataset and use Seaborn to plot the data
Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:
/tests
/tests using the Jest framework
/tests ensure the function rejects an empty list
The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:
Add tests for a JavaScript function that should sum a list of integers
You can ask Copilot about security alerts in repositories in your organization from GitHub Advanced Security features (code scanning, secret scanning, and Dependabot alerts). For example:
How would I fix this alert?
How many alerts do I have on this pull request?
Which line of code is this code scanning alert referencing?
What library is affected by this Dependabot alert?
Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:
/tests
/tests using the Jest framework
/tests ensure the function rejects an empty list
The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:
Add tests for a JavaScript function that should sum a list of integers
Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:
/tests
/tests using the Jest framework
/tests ensure the function rejects an empty list
The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:
Add tests for a JavaScript function that should sum a list of integers
You can ask Copilot Chat questions about security alerts in repositories in your organization from GitHub Advanced Security features (code scanning, secret scanning, and Dependabot alerts). For example:
How would I fix this alert?
How many alerts do I have on this pull request?
Which line of code is this code scanning alert referencing?
What library is affected by this Dependabot alert?
You can ask Copilot Chat questions about the file that's currently displayed in the editor, or about files you have attached to your conversation in the Copilot Chat panel. To give Copilot the correct context:
Open the relevant file in the editor.
Click the paperclip icon in the Copilot Chat panel, then search for and select files you want to attach to the conversation.
For example:
how can I make this file run faster
how are these files related (with two or more attached files)
Use the /tests slash command to ask Copilot to write tests for the active file or selected code. For example:
/tests
/tests using the Jest framework
/tests ensure the function rejects an empty list
The /tests slash command writes tests for existing code. If you prefer to write tests before writing code (test driven development), omit the /tests command. For example:
Add tests for a JavaScript function that should sum a list of integers