|
| 1 | +--- |
| 2 | +title: "Essential GitHub Copilot Chat Commands and Variables" |
| 3 | +description: "Master GitHub Copilot Chat with essential commands, chat variables, and expert participants to boost your productivity" |
| 4 | +category: "GitHub Copilot" |
| 5 | +tags: ["github-copilot", "productivity", "chat-commands", "tips"] |
| 6 | +difficulty: "Beginner" |
| 7 | +author: "GitHub Copilot" |
| 8 | +publishedDate: "2025-06-10" |
| 9 | +lastModified: "2025-06-10" |
| 10 | +--- |
| 11 | + |
| 12 | +# Essential GitHub Copilot Chat Commands and Variables |
| 13 | + |
| 14 | +GitHub Copilot Chat offers powerful commands and variables to help you code more efficiently. This guide covers essential slash commands, chat variables, and specialized chat participants that can enhance your development workflow. |
| 15 | + |
| 16 | +## Quick Reference Guide |
| 17 | + |
| 18 | +### Slash Commands |
| 19 | + |
| 20 | +Start your chat with these useful commands: |
| 21 | + |
| 22 | +```plaintext |
| 23 | +/explain - Explain how code works |
| 24 | +/fix - Get fixes for problems |
| 25 | +/tests - Generate unit tests |
| 26 | +/doc - Add documentation comments |
| 27 | +/new - Create a new project |
| 28 | +``` |
| 29 | + |
| 30 | +Example usage: |
| 31 | +```plaintext |
| 32 | +/explain |
| 33 | +// Your code will be explained in detail |
| 34 | +
|
| 35 | +/fix |
| 36 | +// Copilot will suggest fixes for highlighted issues |
| 37 | +
|
| 38 | +/tests |
| 39 | +// Generates comprehensive unit tests for your code |
| 40 | +``` |
| 41 | + |
| 42 | +### Chat Variables |
| 43 | + |
| 44 | +Include specific context by using these variables: |
| 45 | + |
| 46 | +```plaintext |
| 47 | +#file - Include current file content |
| 48 | +#selection - Include selected text |
| 49 | +#block - Include current code block |
| 50 | +#function - Include current function/method |
| 51 | +#project - Include project context |
| 52 | +``` |
| 53 | + |
| 54 | +Example usage: |
| 55 | +```plaintext |
| 56 | +Explain how #function works |
| 57 | +// Explains the function you're currently in |
| 58 | +
|
| 59 | +What dependencies does #file have? |
| 60 | +// Analyzes current file's dependencies |
| 61 | +
|
| 62 | +How can I improve #selection? |
| 63 | +// Gets suggestions for selected code |
| 64 | +``` |
| 65 | + |
| 66 | +### Expert Chat Participants |
| 67 | + |
| 68 | +Engage specialized experts with @ mentions: |
| 69 | + |
| 70 | +```plaintext |
| 71 | +@workspace - For project structure and patterns |
| 72 | +@terminal - For shell command help |
| 73 | +@vscode - For VS Code features help |
| 74 | +@azure - For Azure services guidance |
| 75 | +``` |
| 76 | + |
| 77 | +Example usage: |
| 78 | +```plaintext |
| 79 | +@workspace What's the best place to add this new feature? |
| 80 | +// Gets project-aware suggestions |
| 81 | +
|
| 82 | +@terminal How do I set up this development environment? |
| 83 | +// Gets terminal command guidance |
| 84 | +
|
| 85 | +@azure How do I deploy this to Azure? |
| 86 | +// Gets Azure-specific deployment help |
| 87 | +``` |
| 88 | + |
| 89 | +## Pro Tips |
| 90 | + |
| 91 | +1. **Combine Commands and Variables** |
| 92 | + ```plaintext |
| 93 | + /explain #selection |
| 94 | + // Get detailed explanation of selected code |
| 95 | + ``` |
| 96 | + |
| 97 | +2. **Use Project Context** |
| 98 | + ```plaintext |
| 99 | + @workspace Is #file following our project patterns? |
| 100 | + // Gets project-aware code review |
| 101 | + ``` |
| 102 | + |
| 103 | +3. **Get Specific Help** |
| 104 | + ```plaintext |
| 105 | + @vscode What's the best way to debug #function? |
| 106 | + // Gets VS Code-specific debugging tips |
| 107 | + ``` |
| 108 | + |
| 109 | +## Best Practices |
| 110 | + |
| 111 | +1. **Start Broad, Then Narrow Down** |
| 112 | + - Begin with general queries |
| 113 | + - Use variables to add specific context |
| 114 | + - Engage expert participants for specialized help |
| 115 | + |
| 116 | +2. **Leverage Multiple Tools** |
| 117 | + - Combine slash commands with variables |
| 118 | + - Use expert participants for domain-specific questions |
| 119 | + - Reference multiple files when needed |
| 120 | + |
| 121 | +3. **Maintain Context** |
| 122 | + - Use #project for broader context |
| 123 | + - Reference specific code with #selection or #block |
| 124 | + - Switch experts when changing domains |
| 125 | + |
| 126 | +## Common Scenarios |
| 127 | + |
| 128 | +### Code Review |
| 129 | +```plaintext |
| 130 | +@workspace Review #file for potential improvements |
| 131 | +/fix #selection |
| 132 | +@terminal How can I test these changes? |
| 133 | +``` |
| 134 | + |
| 135 | +### Documentation |
| 136 | +```plaintext |
| 137 | +/doc #function |
| 138 | +@workspace How should I document this API? |
| 139 | +``` |
| 140 | + |
| 141 | +### Project Architecture |
| 142 | +```plaintext |
| 143 | +@workspace How does #file fit into our architecture? |
| 144 | +@azure What's the best way to structure this for Azure deployment? |
| 145 | +``` |
| 146 | + |
| 147 | +## Working with Multiple Files |
| 148 | +```plaintext |
| 149 | +Compare implementation between #file and <filename> |
| 150 | +@workspace How are these components connected? |
| 151 | +``` |
| 152 | + |
| 153 | +## Reference |
| 154 | + |
| 155 | +For a complete reference of all available commands and features, visit the [GitHub Copilot Chat Cheat Sheet](https://docs.github.com/en/copilot/using-github-copilot/copilot-chat/github-copilot-chat-cheat-sheet). |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +*Pro Tip: Keep this guide handy while working with Copilot Chat. The more you use these commands and variables, the more natural and efficient your coding workflow will become.* |
0 commit comments