Getting Started with GitHub Copilot #2
Length:
8 min
Published:
November 26, 2025

This follows up on part one, "How to get started with GitHub Copilot? #1", where we covered its main features, setup, and first steps. If you missed that article, start there.
Now we move on and show you what else Copilot helps with: refactoring, optimization, and test generation.
This is where Copilot delivers concrete results. Teams that use it fully report shorter code editing times, faster test generation, and higher-quality output. Developers spend less time on routine and more on the parts of the application that matter.
What Copilot brings to the table:
- Refactoring up to 40% faster, because it finds and modifies complex functions for you.
- Roughly 50% time saved when generating unit, integration, and E2E tests.
- Better readability, more stable code, and less technical debt.
- Easier developer onboarding, because it explains the code automatically.
- Better development metrics such as cycle time and deployment frequency.
Refactoring and optimization
Copilot is useful not only for writing new code, but also for changing existing code. It improves readability, structure, and performance.
Examples of use:
Splitting long functions
Mark a complex function and ask Copilot to break it into logical, separate parts:
def process_data_and_generate_report(data):
# loading, cleaning, analysis, report generation...
pass
# Prompt in Copilot Chat:
# "/refactor Split this function `process_data_and_generate_report` into smaller parts."
# One of Copilot's possible suggestions:
def load_data(data):
pass
def clean_data(data):
pass
def analyze_data(data):
pass
def generate_report(data):
pass
Renaming variables/functions
Ask Copilot for more meaningful names:
tmp = 10
# Prompt:
# "Rename `tmp` to a more descriptive name."
# Copilot might suggest:
customer_age = 10
Simplifying logic
For example, you can make complex conditions clearer:
if (user.isAdmin === true && user.isActive === true && user.hasPermission('edit')) {
// ...
}
// Prompt:
// "/refactor Simplify this condition"
// Copilot may suggest:
if (user.isAdmin && user.isActive && user.hasPermission('edit')) {
// ...
}
Performance optimization
Copilot can suggest more efficient data structures or algorithms:
# Original:
for i in range(len(my_list)):
if my_list[i] == value:
# ...
# Prompt:
# "/optimize This loop for better performance"
# Copilot's suggestion:
if value in my_list:
# ...
Slash commands in Copilot Chat for refactoring
/refactorrefactors the selected block according to your input,/optimizesuggests performance improvements,/explainexplains what the code block does, so you understand it before editing.
Source: GitHub Docs
Testing and debugging
Here Copilot combines test generation with support for debugging and bug fixing. It speeds up development and raises code quality.
Test generation
- Use
/testsin Copilot Chat (or highlight the code in the editor) and Copilot designs unit tests for your function. - Copilot creates tests for methods, covers edge cases, and handles exceptions.
- Experimentally, you can use
/setupTests, which sets up a test environment for the whole project (selects a framework, creates a file, and so on).
Debugging and bug fixes
- Mark the broken code and use
/fix. Copilot offers the corrected version. - When a test fails, use
/fixTestFailure. Copilot analyzes the failure and suggests a fix. - In experimental mode, run
/startDebuggingto create a debugging configuration ("launch configuration") and start debugging directly from Copilot Chat.
Code sample + prompt
def compute_factorial(n):
factorial = 1
for i in range(1, n + 1):
factorial *= i * factorial # bug: multiplies by factorial extra
return factorial
Prompt for debugging:
/explain Why does this function compute factorial incorrectly?
After that:
/fix Fix the logic so it calculates factorial correctly.
Copilot can suggest a corrected version:
def compute_factorial(n):
factorial = 1
for i in range(1, n + 1):
factorial *= i
return factorial
Documentation and onboarding
This section shows how Copilot makes it easier to write documentation and bring new developers onto the project.
Documentation
- Use the
/doccommand to let Copilot generate docstrings, comments, or descriptions of functions and classes. - For code that is complex or undocumented, Copilot can explain it and add the comments it needs.
Onboarding new developers
- A newcomer can ask Copilot Chat "What does this part of the code do?" and get a clear explanation.
- When creating a new module or part of an application, developers can ask Copilot to generate the project skeleton: folders, tests, configuration files, and so on.
- Documentation that is created automatically (docstrings, comments) lowers the barrier for new team members and speeds up their onboarding.
Conclusion
GitHub Copilot is more than a tool for quickly writing new code. It's an assistant that helps with the work developers tend to put off: refactoring, optimizing, and generating tests. This is exactly where it delivers immediate results, from faster development and less technical debt to better-quality code and higher test coverage.
In the next article, we'll cover how to improve the quality of Copilot's output and go over advanced features and integrations.
Want to stay one step ahead?
Don't miss our best insights. No spam, just practical analyses, invitations to exclusive events, and podcast summaries delivered straight to your inbox.