GitHub Copilot Prompts & Comment Patterns
Copilot's quality depends heavily on the context you give it — comments, function names, and open tabs all steer suggestions. These patterns get more accurate completions and better Copilot Chat answers.
Comment-Driven Completions
// Validate [INPUT TYPE]: check for [SPECIFIC RULES], throw a descriptive error if invalid// Fetch [DATA] from [API/DB], handle timeout and network errors, retry once before failing// Convert [FORMAT A] to [FORMAT B], preserving [SPECIFIC FIELDS]// TODO: refactor this to use [PATTERN/LIBRARY] instead of [CURRENT APPROACH]
Copilot Chat — Debugging & Review
/explain why this function might fail with [SPECIFIC INPUT]/fix this error, explaining the root cause before the fix: [PASTE ERROR]Review this diff for edge cases I might have missed, focusing on null/undefined handling and off-by-one errors.Suggest 3 test cases that would have caught this bug: [PASTE BUGGY CODE]
Copilot Chat — Generating Code
/tests generate unit tests for this function covering happy path, empty input, and error casesWrite a [LANGUAGE] class for [PURPOSE] following the same style as [OPEN FILE/PATTERN].Refactor this function to reduce nesting and improve readability without changing behavior: [PASTE CODE]
Tips for Better Results
- Keep relevant files open in other tabs — Copilot reads open-tab context, not just the current file.
- Write the function signature and a comment first; let Copilot fill the body rather than guessing from nothing.
- Accept partial suggestions (word-by-word with Tab) when only part of a completion is right.
- Use Copilot Chat's /fix and /explain for debugging — faster than pasting into a separate chatbot.
New to GitHub Copilot? Start with the step-by-step guide.
◆ HOW TO USE GITHUB COPILOT