GitHub Copilot is an AI-powered coding assistant that works inside Visual Studio Code (VS Code). It helps developers write code faster, understand existing programs, fix errors, generate unit tests, and improve code quality.
Unlike traditional code editors, GitHub Copilot uses artificial intelligence to understand the context of your code and suggest relevant implementations.
In this tutorial, you will learn how to install GitHub Copilot, connect your GitHub account, use inline code suggestions, work with Copilot Chat and Agent Mode, and create custom AI agents for your development projects.
We will also explore practical Python examples to understand how Copilot helps developers in everyday programming tasks.
1. What You Need Before Using GitHub Copilot
Before getting started, make sure you have the following:
- Visual Studio Code installed on your computer.
- An active GitHub account.
- Access to a GitHub Copilot plan, Free plan, or eligible organizational subscription.
- An internet connection.
GitHub Copilot offers different subscription options. The available features and usage limits depend on your plan.
You can check the latest subscription details on the official GitHub Copilot Plans page.
2. How to Install GitHub Copilot in VS Code
Follow these steps to install GitHub Copilot.
- Open Visual Studio Code.
- Open the Extensions view from the left sidebar.
- Alternatively, press
Ctrl + Shift + Xon Windows or Linux, orCmd + Shift + Xon macOS. - Search for GitHub Copilot.
- Install the official GitHub Copilot extension.
- Install GitHub Copilot Chat if it is listed separately in your VS Code version.
Screenshot suggestion: Capture the VS Code Extensions marketplace showing the official GitHub Copilot extension.
3. How to Sign In to GitHub Copilot
After installing the extension, connect your GitHub account.
- Open the Copilot icon or notification in VS Code.
- Select Sign in to GitHub.
- Your default browser opens the GitHub authentication page.
- Sign in using your GitHub account.
- Review and authorize the Visual Studio Code connection.
- Return to VS Code.
Once authentication is complete, GitHub Copilot is ready to use, subject to your subscription and usage limits.
4. Main GitHub Copilot Features in VS Code
GitHub Copilot provides several features to help developers throughout the coding process.
4.1 Inline Code Completions
Inline code completion is one of the most useful Copilot features.
As you type code, Copilot displays suggestions in gray text near your cursor. These suggestions are generated using the surrounding code and available context.
You can accept or reject suggestions using keyboard shortcuts.
| Action | Shortcut |
|---|---|
| Accept suggestion | Tab |
| Reject suggestion | Esc |
| Accept next word | Ctrl + Right Arrow |
| View next suggestion | Alt + ] |
| View previous suggestion | Alt + [ |
On macOS, use the corresponding Command or Option shortcuts where applicable.
Practical example
Create a Python file named calculate.py.
Enter this comment:
# Create a function to calculate the average<br># of a list of numbers.<br># Handle empty lists safely.Wait for Copilot to suggest the implementation.
Press Tab to accept the suggestion.
You can also continue typing to refine the generated code.
4.2 Generate Code from Comments
GitHub Copilot can convert natural-language comments into working code.
For example, enter the following comment in a Python file:
# Create a function that accepts a list of numbers.
# Calculate the total and average.
# Handle an empty list without raising an error.Copilot may suggest an implementation similar to this:
def calculate_average(numbers):
if not numbers:
return 0
total = sum(numbers)
average = total / len(numbers)
return average
values = [10, 20, 30, 40]
print(calculate_average(values))Output:
25.0The generated code is an example. Always review and test the suggestion before using it in your application.
4.3 Use GitHub Copilot Chat in VS Code
Copilot Chat provides a conversational interface directly inside VS Code.
You can ask questions about your source code, request explanations, identify bugs, and generate new implementations.
Common tasks include:
- Explain an existing Python function.
- Identify errors in SQL queries.
- Refactor complex code.
- Generate unit tests.
- Explain unfamiliar programming concepts.
You can open Copilot Chat from the VS Code Chat icon or use the configured keyboard shortcut.
You can also select a section of code and ask Copilot to explain or improve it.
Useful prompts
/explain
Explain this Python function in simple terms./fix
Find the error in the selected code
and suggest a corrected implementation./tests
Generate pytest unit tests for this function.
Include normal and boundary test cases.Available commands and functionality can vary by VS Code and Copilot version.
4.4 Copilot Chat vs Agent Mode
Copilot Chat and Agent Mode serve different development purposes.
Copilot Chat
Use Chat when you want to ask questions, understand code,e or get suggestions.
Example:
Explain the execution flow of this Python file.
Identify possible performance issues.
Do not modify the source code.Agent Mode
Agent Mode is useful when you want Copilot to complete a multi-step development task.
For example:
Analyze my Python project.
Identify functions without exception handling.
Improve error handling where required.
Generate pytest unit tests.
Run the tests and explain any failures.
Show me the proposed changes before I accept them.Copilot can inspect relevant project files, propose changes,es and use available tools to execute tasks.
| Feature | Chat | Agent Mode |
|---|---|---|
| Explain code | Yes | Yes |
| Answer technical questions | Yes | Yes |
| Suggest code improvements | Yes | Yes |
| Modify project files | Depends on workflow | Yes |
| Work across multiple files | Limited | Yes |
| Execute tools and tests | Depends on configuration | Yes, with available tools and permissions |
When should you use them?
Use Chat for learning, explanations, and troubleshooting. Use Agent Mode for multi-step development tasks, implementation, and testing.
5. Practical Example: Generate Python Code Using Copilot
Let’s explore a real-world example.
Suppose you are developing a sales data processing application. You need to read a CSV file, remove duplicates, handle missing customer IDs, and calculate total sales.
Create a file named sales_analysis.py.
Enter this prompt in Copilot Chat:
Create a Python function that:
1. Reads sales data from a CSV file using Pandas.
2. Removes duplicate records.
3. Removes records with missing customer IDs.
4. Calculates total sales by customer.
5. Saves the output to a new CSV file.
Include exception handling and meaningful comments.Copilot can generate the implementation.
For example:
import pandas as pd
def process_sales(input_file, output_file):
try:
df = pd.read_csv(input_file)
df = df.drop_duplicates()
df = df.dropna(subset=["customer_id"])
result = (
df.groupby("customer_id", as_index=False)["sales"]
.sum()
)
result.to_csv(output_file, index=False)
print("Sales analysis completed.")
except FileNotFoundError:
print("Input file not found.")
except Exception as error:
print(f"Processing failed: {error}")
process_sales("sales.csv", "sales_summary.csv")Expected output
Sales analysis completed.This example demonstrates how Copilot can help developers generate practical data processing code from natural-language instructions.
Review the generated implementation, validate column name,s and test it with sample data.

6. Debug Python Errors Using GitHub Copilot
/Debug
You must be logged in to post a comment.