Introduction
If you're a developer who uses AI daily, you know GitHub Copilot is more than just an autocomplete tool. It can write commit messages, explain complex code, generate documentation, and even review pull requests. But to get the most out of it, you need the right prompts. This article collects 15 battle-tested prompts that I actually use in my workflow — from generating commit messages to conducting thorough code reviews. Each prompt includes a real usage example, so you can copy-paste and adapt immediately. No fluff, just practical value.
Why Prompts Matter for Copilot
GitHub Copilot (now powered by GPT-4 and available as Copilot Chat) responds to natural language instructions. The quality of its output depends heavily on how you phrase your request. A vague "explain this code" gives a generic explanation, while a structured prompt like "Explain this function in simple terms, mention edge cases, and suggest improvements" yields actionable insights. Over the past year, I've refined these prompts through daily use — they work for JavaScript, Python, TypeScript, Go, and most modern languages.
1. Generating Commit Messages
Prompt: "Write a concise, conventional commit message for the following diff. Use the format: type(scope): description. Types: feat, fix, refactor, docs, test, chore. Keep the description under 50 characters."
Example: Paste the diff. Copilot outputs: fix(auth): handle token expiration in middleware.
2. Writing Unit Tests
Prompt: "Generate Jest unit tests for the following function. Include tests for: standard input, edge cases (null, empty, undefined), and error handling. Use describe/it blocks. Cover at least 5 scenarios."
Example: Paste a function that parses CSV. Copilot generates tests for empty rows, invalid delimiters, and large files.
3. Explaining Code (for Code Review)
Prompt: "Explain this code as if to a junior developer. Break it down step by step. Mention any potential bugs, performance issues, or security concerns. Suggest one improvement."
Example: Paste a recursive function. Copilot explains recursion depth limits and recommends an iterative approach.
4. Generating Code Documentation
Prompt: "Write JSDoc comments for this function. Include @param, @returns, @throws, and a brief description. Use TypeScript types."
Example: Paste a function that fetches user data. Copilot adds complete documentation with parameter descriptions.
5. Reviewing a Pull Request
Prompt: "Act as a senior code reviewer. Analyze the following diff. Check for: code style consistency, potential bugs, performance bottlenecks, security vulnerabilities (like SQL injection, XSS), and adherence to SOLID principles. Provide a summary with 3-5 specific recommendations."
Example: Paste a PR with a new API endpoint. Copilot flags missing input validation and suggests using a transaction.
6. Refactoring Code
Prompt: "Refactor this function to be more readable and maintainable. Apply the Single Responsibility Principle. Extract helper functions where appropriate. Use modern JavaScript (ES2024) syntax. Show the before and after."
Example: Paste a long function with mixed concerns. Copilot splits it into smaller functions and uses optional chaining.
7. Debugging an Error
Prompt: "I'm getting this error: [paste error]. Here is the relevant code. What is the most likely cause? Provide a fix and explain why it works. Consider edge cases."
Example: Paste a TypeError. Copilot identifies undefined variable and suggests a null check.
8. Generating Configuration Files
Prompt: "Generate a .eslintrc.json configuration file for a React project using TypeScript. Include rules for: import ordering, no unused variables, and React hooks. Use the recommended presets."
Example: Copilot outputs a complete config with eslint-plugin-react and @typescript-eslint.
9. Writing API Client Code
Prompt: "Write a fetch wrapper in TypeScript that handles GET, POST, PUT, DELETE requests. Include: base URL, authentication header, error handling, and retry logic (2 retries with exponential backoff). Use async/await."
Example: Copilot generates a reusable apiClient object with a request method.
10. Generating Regex Patterns
Prompt: "Write a regex that matches valid email addresses according to RFC 5322. Explain each part of the regex. Also provide a simpler version that covers 95% of real-world cases."
Example: Copilot outputs a regex pattern and explains character classes, quantifiers, and anchors.
11. Creating Database Queries
Prompt: "Write a SQL query to find the top 10 customers by total order value in the last 30 days. Use PostgreSQL syntax. Include: JOINs, GROUP BY, HAVING, and ORDER BY. Optimize for performance."
Example: Copilot generates a query with proper indexing hints.
12. Converting Code Between Languages
Prompt: "Convert this Python function to idiomatic Go. Use proper error handling, zero values, and goroutines where appropriate. Explain the key differences."
Example: Paste a Python file parser. Copilot returns a Go version using defer, io.Reader, and error wrapping.
13. Generating Commit Descriptions for Multiple Files
Prompt: "Given the following list of changed files and their summaries, write a commit message that describes the overall change. Use imperative mood. List each file's purpose in bullet points."
Example: Paste a list of 5 files. Copilot writes a message like "Add user avatar upload functionality" with file-by-file breakdown.
14. Creating a README Section
Prompt: "Write a 'Getting Started' section for a CLI tool. Include: prerequisites (Node.js 18+), installation via npm, basic usage example with flags, and a troubleshooting tip."
Example: Copilot outputs a well-structured section with code blocks.
15. Code Review Checklist Generation
Prompt: "Create a code review checklist for a team that uses TypeScript, React, and Node.js. Include categories: functionality, security, performance, readability, test coverage, and error handling. Add 3-5 items per category."
Example: Copilot produces a Markdown checklist ready to paste into PR templates.
Practical Tips for Better Prompts
- Be specific: include language, framework, and constraints.
- Provide context: paste relevant code or error messages.
- Ask for explanations: "Explain why this works" improves understanding.
- Iterate: if output is off, refine your prompt with more details.
Conclusion
GitHub Copilot is a powerful assistant, but its value depends on the quality of your prompts. The 15 prompts above cover the most common developer tasks — from writing commits to reviewing code. Start with these, adapt them to your stack, and you'll save hours each week. Remember: the best prompt is the one that gets you a useful answer on the first try. Keep experimenting, and soon you'll develop your own library of go-to prompts for any situation.
Comments