GitHub Copilot

GitHub Copilot — User Guide

Industry-standard AI pair programmer for code completion and generation.

Visit website Paid Sign-up required
Strengths
  • Deeply integrated with mainstream IDEs such as VS Code and JetBrains, no need to switch tools
  • Real-time code completion, understand the context, complete the entire function instead of a single line
  • Copilot Chat can chat directly in the editor, explain the code and generate tests
  • Supports GitHub repository-level contextual understanding
  • The enterprise version supports private code base training to protect code privacy
Best for
  • Daily coding acceleration: automatic completion of functions, classes, and comments
  • Quickly generate sample code (CRUD, API interface, test cases)
  • Code interpretation: understanding other people’s code or legacy code
  • Unit test generation: automatically generate test cases for functions
  • Code Refactoring: Refactor and explain changes directly within the IDE

Basic usage in VS Code

The most powerful thing about Copilot is its seamless integration within the IDE. Here is the core usage.

Scenario

Annotation-driven code generation

Prompt example
In VS Code, write a comment:




# Function: parse the date string entered by the user


# Supported formats: YYYY-MM-DD, DD/MM/YYYY, MM-DD-YYYY


# Return: datetime object, return None if parsing fails


# Contains error handling and logging


def parse_date(date_str: str):
Output / what to expect

Copilot will automatically complete the complete function:

  • Use dateutil.parser or manually parse multiple formats

  • Contains try/except error handling

  • Add logging logging

  • Return type annotation is correct

Press Tab to accept a suggestion, Alt+] to view the next suggestion.

Tips

The more detailed the comments, the more accurate the generated code will be. Annotations in Chinese are also perfectly fine.

Scenario

Explain complex code using Copilot Chat

Prompt example
Select a piece of complex code and enter it in Copilot Chat:




/explain




Or:


What does this code do? Are there any potential performance issues?
Output / what to expect

Copilot Chat will:

  1. Explain the code logic in natural language (line by line or as a whole)

  2. Point out potential problems (such as: O(n²) complexity, memory leak risk)

  3. Suggest optimization solutions

Tips

You can also quickly explain it by right-clicking on the code → "Copilot" → "Explain This".

Generate test cases

Copilot can automatically generate complete unit tests for your functions.

Scenario

Generate tests for existing functions

Prompt example
In Copilot Chat, select the function and enter:




/tests




Or:


Please generate a complete unit test for this function, using the pytest framework,


Contains: test cases for normal conditions, boundary conditions, and abnormal
conditions.
Output / what to expect
import pytest
from datetime import datetime
from your_module import parse_date

class TestParseDate:
    def test_valid_iso_format(self):
        result = parse_date("2025-03-15")
        assert result == datetime(2025, 3, 15)
    
    def test_valid_slash_format(self):
        result = parse_date("15/03/2025")
        assert result == datetime(2025, 3, 15)
    
    def test_invalid_date_returns_none(self):
        result = parse_date("not-a-date")
        assert result is None
    
    def test_empty_string_returns_none(self):
        result = parse_date("")
        assert result is None
Tips

After generation, check whether the test cases cover the edge cases you care about, and add them manually if necessary.

Copilot CLI (command line)

Copilot also supports the command line to help you generate shell commands.

Scenario

Generate shell commands in natural language

Prompt example
In the terminal:




gh copilot suggest "Find all files larger than 100MB in the current directory
and sort them by size"
Output / what to expect

Copilot recommends:

find . -type f -size +100M -exec ls -lh {} ; | sort -k5 -rh

And explain the meaning of each parameter, and you can execute it directly after confirmation.

Tips

Install the GitHub CLI and run `gh extension install github/gh-copilot` to enable this feature.

Compared with similar tools

ToolStrengthBest forPricing
GitHub Copilot This toolIDE has the deepest integration, smoothest completion, and enterprise-level securityProfessional developers’ daily coding, enterprise teams$10/month for individuals, $19/user/month for businesses
CursorAI native IDE, stronger conversational programming experienceScenarios that require large-scale code reconstruction and multi-file collaborationFree version / Pro $20/month
TabnineIt can be deployed locally and the code does not need to be uploaded to the cloud.Enterprises with extremely high code privacy requirementsFree version / Pro $12/month
Amazon CodeWhispererDeep integration with AWS servicesAWS DeveloperPersonal version free