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.
You can think of it as a coding partner who has seen vast amounts of code and can suggest what to write next — whether it's a single line or a complete function.
The output you get depends on how well you communicate your intention.
Prompt engineering is just guiding Copilot with clear, structured input.
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 works much like predictive text — trained not on sentences but on code.
You mainly use it in two ways:
Inline Suggestions
These appear as you type. Best for completing small logic blocks, boilerplate, or finishing functions.
Copilot Chat
Here you can ask questions, request refactoring, or generate tests.
This mode helps when you need more control or explanation.
How Prompting Actually Works
Under the hood, Copilot follows a basic pipeline:
- Gathers context from your workspace
- Selects the most relevant parts
- Feeds them into the language model
- Formats and sends you a suggestion
So when you give good context, you get better 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 work
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.
*/
Adding a purpose or description at the top helps Copilot set direction.
3. Break Large Tasks into Steps
✅ Better Approach
# Step 1: Validate email
# Step 2: Hash password
# Step 3: Create user record
Copilot handles tasks better when they are broken into smaller steps.
4. Give Examples
✅ Good Example
// Input: 1234.56, "USD"
// Output: "$1,234.56"
function formatCurrency(amount, currency) {
// ...
}
Examples help Copilot follow the pattern you expect.
5. Use Proper Naming and Comments
✅ Good Example
def calculate_monthly_payment(loan_amount, annual_rate, years):
"""Calculate monthly payment for a loan."""
Clear names and short docstrings guide Copilot's reasoning.
Common Mistakes to Avoid
❌ Pitfall 1: Vague or Ambiguous Prompts
Poor Example
# Fix this function
def process_data(data):
pass
✅ Better 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]:
pass
❌ Pitfall 2: Inconsistent Code Style
Poor Example
function getUserData() {} // camelCase
function get_user_profile() {} // snake_case
const USERAPI = ""; // inconsistent
✅ Better Example
const API_BASE_URL = "https://api.example.com"; // SCREAMING_SNAKE_CASE
function getUserData() {} // camelCase
function getUserProfile() {} // consistent naming
Stick to a clear naming convention. Copilot follows your code style.
❌ Pitfall 3: Too Many Open Tabs
Copilot performs best when 1–3 related files are open.
Too many tabs confuse its context engine.
❌ Pitfall 4: Missing Examples
Poor Example
# Create a data validation function
✅ Better 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:
pass
Whenever possible, show at least one sample input and expected output.
Final Thoughts
Copilot changes the way we write code. It doesn't replace us — it saves us time and helps us think more clearly while writing.
Clarity in your comments, consistent naming, and good context make Copilot more useful. Over time, you'll see it start to adapt to your style and generate better suggestions.
Prompting well is not about tricks or magic. It's about clear communication and structure — skills every developer can master.