
GitHub Copilot — User Guide
Industry-standard AI pair programmer for code completion and generation.
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.
Annotation-driven code generation
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):
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.
The more detailed the comments, the more accurate the generated code will be. Annotations in Chinese are also perfectly fine.
Explain complex code using Copilot Chat
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?
Copilot Chat will:
Explain the code logic in natural language (line by line or as a whole)
Point out potential problems (such as: O(n²) complexity, memory leak risk)
Suggest optimization solutions
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.
Generate tests for existing functions
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.
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
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.
Generate shell commands in natural language
In the terminal: gh copilot suggest "Find all files larger than 100MB in the current directory and sort them by size"
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.
Install the GitHub CLI and run `gh extension install github/gh-copilot` to enable this feature.
Compared with similar tools
| Tool | Strength | Best for | Pricing |
|---|---|---|---|
| GitHub Copilot This tool | IDE has the deepest integration, smoothest completion, and enterprise-level security | Professional developers’ daily coding, enterprise teams | $10/month for individuals, $19/user/month for businesses |
| Cursor | AI native IDE, stronger conversational programming experience | Scenarios that require large-scale code reconstruction and multi-file collaboration | Free version / Pro $20/month |
| Tabnine | It can be deployed locally and the code does not need to be uploaded to the cloud. | Enterprises with extremely high code privacy requirements | Free version / Pro $12/month |
| Amazon CodeWhisperer | Deep integration with AWS services | AWS Developer | Personal version free |
Sources & references:
- GitHub Copilot official documentation (2025-03)
- GitHub Copilot Shortcut Key Reference (2025-03)