GitHub Copilot Tips: 10 Tricks Every Developer Should Know
GitHub Copilot Tips: 10 Tricks Every Developer Should Know
GitHub Copilot has transformed how developers write code. But are you using it to its full potential? Here are 10 tips that will supercharge your Copilot experience.
1. Write Detailed Comments First
Copilot generates better code when it understands context. Write a detailed comment before you start coding:
// Function to validate email addresses
// - Check for @ symbol
// - Verify domain has at least one dot
// - Return true if valid, false otherwise
// - Handle edge cases like empty strings
function validateEmail(email) {
// Copilot will generate excellent code here
}
2. Use Copilot Chat for Explanations
Press Cmd+I (Mac) or Ctrl+I (Windows) to open Copilot Chat. Ask it to:
3. Accept Partial Suggestions
You don't have to accept the entire suggestion. Use:
4. Provide Examples in Comments
Copilot learns from examples:
# Convert temperature
# Example: celsius_to_fahrenheit(0) -> 32
# Example: celsius_to_fahrenheit(100) -> 212
def celsius_to_fahrenheit(celsius):
# Copilot now understands exactly what you want
5. Use Slash Commands in Chat
Copilot Chat supports powerful slash commands:
/explain: Explain selected code/fix: Fix problems in code/tests: Generate unit tests/doc: Add documentation/simplify: Simplify complex code6. Create Custom Snippets
Train Copilot on your patterns by keeping example files:
// In a file called "patterns.ts" (don't import, just keep open)
// Copilot will learn these patterns
// Pattern: API endpoint with error handling
async function apiEndpoint(req, res) {
try {
const data = await service.getData();
res.json({ success: true, data });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
}
7. Use the @workspace Agent
In Copilot Chat, use @workspace to ask questions about your entire codebase:
8. Generate Tests Automatically
Select a function and use /tests in chat:
/tests for the validateEmail function
Copilot will generate comprehensive test cases including edge cases.
9. Iterate with Follow-ups
Don't accept the first suggestion. Ask follow-up questions:
10. Use Keyboard Shortcuts
Master these shortcuts:
| Action | Mac | Windows |
|--------|-----|---------|
| Show suggestions | Opt+\ | Alt+\ |
| Next suggestion | Opt+] | Alt+] |
| Previous suggestion | Opt+[ | Alt+[ |
| Accept suggestion | Tab | Tab |
| Dismiss | Esc | Esc |
| Open Chat | Cmd+I | Ctrl+I |
Bonus: Configure Copilot Settings
In VS Code settings, customize:
Common Mistakes to Avoid
Conclusion
GitHub Copilot is more than autocomplete—it's a coding partner. These tips will help you collaborate more effectively with AI and write better code faster.
Alex Chen
AIToolScout contributor