It's been more than four years since I started using GitHub Copilot.
I've used it nearly every day since it first appeared as a simple autocomplete tool. Over time, I've picked up many small lessons that help Copilot perform better.
In this post, I'll share what I've learned — from basic usage to advanced prompting techniques — so you can use Copilot more effectively.
What Is GitHub Copilot?
GitHub Copilot (GHCP) is an AI-powered coding assistant built by GitHub and OpenAI.
Think of it as a coding partner who has read millions of repositories and can suggest what to write next — whether it’s a single line or an entire module.
Note
Prompt engineering is simply about communicating clearly with Copilot using structured, contextual instructions.
How GitHub Copilot Works
Copilot predicts your next code based on context. It considers:
- The code around your cursor
- Comments, function names, variable names
- Other open files
- Your full project structure
It behaves like predictive text, but for code.
You mainly use it in two ways:
Inline Suggestions
Appear as you type.
Best for completing small logic blocks, boilerplate, or finishing functions.
Copilot Chat
Used for asking questions, refactoring, or generating tests.
Best when you want control, explanation, or iteration.
How Prompting Actually Works
Under the hood, Copilot follows a simple pipeline:
- Collects context from your editor
- Filters relevant sections
- Feeds them into the model
- Returns the best predicted suggestion
Tip
The better the context, the smarter the output.
Basic Prompting Tips
1. Be Clear About What You Want
Good Example ✅
/* Create a user authentication system with:
* - Email/password login
* - JWT token generation
* - Password hashing with bcrypt
* - Input validation and error handling
*/Poor Example ❌
// Make login workImportant
Be specific about intent, not just the action.
2. Give Context Before You Code
Good Example ✅
/**
* Product API
* Handles CRUD operations for products using Express and MongoDB.
* Includes validation, pagination, and image upload.
*/Tip
Add purpose upfront so Copilot sets the right direction.
3. Break Large Tasks into Steps
Better Approach
# Step 1: Validate email
# Step 2: Hash password
# Step 3: Create user recordTip
Breaking logic into steps improves quality and structure.
4. Give Examples
Good Example ✅
// Input: 1234.56, "USD"
// Output: "$1,234.56"
function formatCurrency(amount, currency) {
// ...
}Tip
Examples teach Copilot patterns and expected formats.
5. Use Proper Naming and Comments
Good Example ✅
def calculate_monthly_payment(loan_amount, annual_rate, years):
"""Calculate monthly payment for a loan."""Tip
Clear names and short docstrings guide Copilot’s reasoning.
Helpful Prompting Do’s and Don’ts
Even small prompt changes can alter Copilot’s behavior. Use this table as a quick reference for daily use.
| ✅ Do | ❌ Don’t | Why |
|---|---|---|
Be specific// Create a REST API for tasks with CRUD endpoints | Be vague// Build API | Vague prompts confuse Copilot’s goal. |
Add structure// Step 1: Validate input\n// Step 2: Save to DB | Dump everything at once | Stepwise prompts improve logical output. |
Show examples// Input: "John"\n// Output: "Hello, John!" | Skip examples | Examples show expected pattern. |
Use clear namescalculate_tax() | Use unclear namesdoStuff() | Copilot mirrors naming style. |
Add constraints// Use async/await and TypeScript | Leave it open-ended | Constraints narrow valid outputs. |
Reference context// Continue from previous function | Start without context | Copilot needs continuity. |
| Keep tabs focused (1–3 files) | Keep many unrelated tabs open | Too many tabs dilute context. |
| Iterate and re-prompt | Accept the first suggestion blindly | Iteration refines quality. |
Example Comparison
Bad Prompt ❌
# Make it workGood Prompt ✅
# Create a CLI tool to track daily expenses
# Features:
# 1. Add and remove entries
# 2. Show total spent
# 3. Save data to a local JSON fileTip
The second prompt gives Copilot structure and direction.
Quick Mental Model
Tip
Treat Copilot like a junior developer:
- If your instruction is vague, expect vague results.
- The clearer your context and structure, the better the output.
- Prompt as if you’re briefing a teammate — purpose first, code second.
Common Mistakes to Avoid
Pitfall 1: Vague or Ambiguous Prompts
Poor Example ❌
# Fix this function
def process_data(data):
passBetter Example
# Fix the user authentication function to:
# 1. Validate email format
# 2. Check password strength
# 3. Hash password using bcrypt
# 4. Handle database errors
def authenticate_user(email: str, password: str) -> Dict[str, Any]:
passImportant
Copilot cannot fix what it doesn’t understand. Define the goal clearly.
Pitfall 2: Inconsistent Code Style
Poor Example ❌
function getUserData() {} // camelCase
function get_user_profile() {} // snake_case
const USERAPI = ""; // inconsistentBetter Example
const API_BASE_URL = "https://api.example.com"; // SCREAMING_SNAKE_CASE
function getUserData() {} // camelCase
function getUserProfile() {} // consistent namingTip
Copilot learns your conventions. Consistency improves accuracy.
Pitfall 3: Too Many Open Tabs
Warning
Copilot performs best when 1–3 related files are open. Too many tabs confuse the context engine and reduce output quality.
Pitfall 4: Missing Examples
Poor Example ❌
# Create a data validation functionBetter Example
# Create a data validation function that:
# Input: {"name": "John", "age": 25, "email": "john@test.com"}
# Output: {"valid": True, "errors": []}
def validate_user_data(data: dict) -> dict:
passTip
Always show at least one sample input and expected output.
Final Thoughts
Copilot doesn’t replace developers — it amplifies clarity and speed.
Write comments that describe the goal, not how to achieve it. Give Copilot structure, examples, and constraints. Iterate until the suggestion aligns with your expectation.
Note
Prompting well is not about tricks. It’s about communication and structure — the same skills that make you a better developer.
