Skip to main content

GitHub Copilot Chat cheat sheet

Use this cheat sheet to quickly reference the most common commands and options for using GitHub Copilot Chat.

This version of this article is for Copilot on the GitHub website. For other versions of this article, click the tabs above.

This version of this article is for Copilot in Visual Studio Code. For other versions of this article, click the tabs above.

This version of this article is for Copilot in Visual Studio. For other versions of this article, click the tabs above.

This version of this article is for Copilot in JetBrains. For other versions of this article, click the tabs above.

About GitHub Copilot enhancements

You can enhance your experience of Copilot Chat with a variety of commands and options. Finding the right command or option for the task you are working on can help you achieve your goals more efficiently. This cheat sheet provides a quick reference to the most common commands and options for using Copilot Chat.

For information about how to get started with Copilot Chat in Visual Studio, see 在 IDE 中向 GitHub Copilot 提问.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by the command name.

Available slash commands may vary, depending on your environment and the context of your chat. To view a list of currently available slash commands, type / in the chat prompt box of your current environment. Below is a list of some of the most common slash commands for using Copilot Chat.

CommandDescription
/helpQuick reference and basics of using GitHub Copilot.
/testsGenerate unit tests for the selected code.
/fixPropose a fix for problems in the selected code.
/explainExplain how the code in your active editor works.
/optimizeAnalyze and improve running time of the selected code.
/docAdd documentation comment for this symbol.

For information about how to get started with Copilot Chat in Visual Studio Code, see 在 IDE 中向 GitHub Copilot 提问.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by the command name.

Available slash commands may vary, depending on your environment and the context of your chat. To view a list of currently available slash commands, type / in the chat prompt box of your current environment. Below is a list of some of the most common slash commands for using Copilot Chat.

CommandDescription
/helpQuick reference and basics of using GitHub Copilot.
/testsGenerate unit tests for the selected code.
/fixPropose a fix for problems in the selected code.
/explainExplain how the code in your active editor works.
/fixTestFailureFind and fix a failing test.
/newCreate a new project.
/clearStart a new chat session.

For information about how to get started with Copilot Chat in JetBrains, see 在 IDE 中向 GitHub Copilot 提问.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by the command name.

Available slash commands may vary, depending on your environment and the context of your chat. To view a list of currently available slash commands, type / in the chat prompt box of your current environment. Below is a list of some of the most common slash commands for using Copilot Chat.

CommandDescription
/helpQuick reference and basics of using GitHub Copilot.
/testsGenerate unit tests for the selected code.
/fixPropose a fix for problems in the selected code.
/explainExplain how the code in your active editor works.
/fixTestFailureFind and fix a failing test.
/newCreate a new project.
/clearStart a new chat session.

For information about how to get started with Copilot Chat in the GitHub website, see 在 GitHub 中向 GitHub Copilot 提问.

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by the command name.

Available slash commands may vary, depending on your environment and the context of your chat. To view a list of currently available slash commands, type / in the chat prompt box of your current environment. Below is a list of some of the most common slash commands for using Copilot Chat.

CommandDescription
/helpQuick reference and basics of using GitHub Copilot.
/searchPerforms a search within the repository, including issues, pull requests, and code.
/fileRetrieves a specific file from the repository by its path.
/renameRename a conversation.
/deleteDelete a conversation.
/newStart a new conversation
/clearClear conversation.

Chat variables

Use chat variables to include specific context in your prompt. To use a chat variable, type # in the chat prompt box, followed by a chat variable.

VariableDescription
#fileIncludes the current file's content in the prompt.
#selectionIncludes the currently selected text in the prompt.
#lineIncludes the current line of code in the prompt.
#projectIncludes the project context in the prompt.
#pathIncludes the file path in the prompt.
#functionIncludes the current function or method in the prompt.
#classIncludes the current class in the prompt.
#commentIncludes the current comment in the prompt.
#blockIncludes the current block of code in the prompt.
#symIncludes the current symbol in the prompt.

References

By default, Copilot Chat will reference the file that you have open or the code that you have selected. You can also use # followed by a file name, file name and line numbers, or solution to reference a specific file, lines, or solution.

ExampleDescription
Where are the tests in #MyFile.cs?References a specific file
How are these files related #MyFile.cs #MyFile2.csReferences multiple files
Explain this function #MyFile.cs: 66-72?References specific lines in a file
Is there a delete method in this #solution?References the current file

Chat participants

Chat participants are like domain experts who have a specialty that they can help you with. You can specify a chat participant by typing @ in the chat prompt box, followed by a chat participant name. To see all available chat participants, type @ in the chat prompt box.

Below is a list of some of the most common chat participants for using Copilot Chat.

VariableDescription
@workspaceHas context about the code in your workspace. Use @workspace when you want Copilot to consider the structure of your project, how different parts of your code interact, or design patterns in your project.
@vscodeHas context about Visual Studio Code commands and features. Use @vscode when you want help with Visual Studio Code.
@terminalHas context about the Visual Studio Code terminal shell and its contents. Use @terminal when you want help creating or debugging terminal commands.
@azureHas context about Azure services and how to use, deploy and manage them. Use @azure when you want help with Azure. The @azure chat participant is currently in 公共预览版 and is subject to change.
@githubAllows you to use GitHub-specific Copilot skills. See 在 IDE 中向 GitHub Copilot 提问.