DXHEROES Logo
What We Do

/

Back to insights

#ai, #guide

Getting Started with GitHub Copilot #2

Length: 

8 min

Published: 

November 26, 2025

This time we'll follow up on the first part of "How to get started with GitHub Copilot? #1", where we covered its main features, setup, and overall first steps to get started. If you missed that article, we recommend starting there.

Now we'll move on a bit and show you what else Copilot can help you with, specifically going over refactoring, optimization and test generation.

It is in these areas that Copilot can deliver very concrete results. Teams that use it to its fullest extent report significant reductions in code editing time, faster test generation, and overall higher quality output. Developers spend less time on routine tasks and can focus more on key parts of the application.

What exactly does Copilot bring to the table:

  • Refactoring faster by up to 40% by identifying and modifying complex functions.
  • Saving up to ~50% of time in generating unit, integration and E2E tests.
  • Improved readability, stability and reduced technical debt.
  • Easier onboarding of developers thanks to automatic code explanation.
  • Improving development metrics such as cycle time and deployment frequency.

Refactoring & Optimization

Copilot is useful not only for writing new code, but also for modifying existing code - improving readability, structure and performance.

Examples of use:

Splitting long functions

You can mark a complex function and ask Copilot to break it down 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

Simplification of logic

For example, complex conditions can be made 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 design 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

  • /refactor - refactors the selected block according to the input
  • /optimize - suggests performance improvements
  • /explain - explains what the code block does, which helps you understand it better before editing

Source: GitHub Docs

Testing & Debugging

In this section, Copilot combines test generation with support for debugging and bug fixing to speed up development and improve code quality.

Test generation

  • Use /tests in Copilot Chat (or highlight the code in the editor) to have Copilot design unit tests according to your function.
  • Copilot can create tests for methods, include edge cases, handle exceptions, etc.
  • Experimentally, you can use /setupTests, which sets up a test environment for the whole project (select a framework, create a file, etc.).

Debugging and bug fixes

  • After marking the wrong code, you can use /fix - Copilot will offer the corrected version.
  • If the test fails, /fixTestFailure can be used - Copilot analyzes the failure and suggests a fix.
  • In experimental mode you can use /startDebugging to 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 & Onboarding

This section is about how Copilot will make it easier to write documentation and get new developers involved in the project.

Documentation

  • You can use the /doc command to let Copilot generate docstrings, comments, or descriptions of functions and classes.
  • For code that is complex or has not been documented, Copilot can explain and add the necessary comments.

Onboarding new developers

  • Newbies can use Copilot Chat for questions like "What does this part of the code do?" and Copilot will give them 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, etc.
  • 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 just a tool for quickly writing new code. It's a powerful assistant that greatly helps with activities that developers often put off - like refactoring, optimizing, or generating tests. And it's in these areas that it can deliver immediate results: from speeding up development and reducing technical debt to better quality code and increased test coverage.

In the next article, we'll summarize how to improve the quality of Copilot's outputs and go over advanced features and integrations.

Back to insights

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.