概述
GitHub Copilot 是由 GitHub 和 OpenAI 联合开发的 AI 编码助手,可根据上下文自动补全代码、生成函数、优化逻辑,甚至编写整个代码模块。作为最早大规模商业化的 AI 编码工具,它深度集成到 VS Code、JetBrains、Visual Studio 等主流 IDE 中。2026 年它新增了 Copilot Agent 模式,可自主完成修复 issue、创建 PR 等端到端任务。注意:自 2026 年 6 月 1 日起,Copilot 订阅计划切换为基于用量的计费模式。
核心特性:深度 IDE 集成、代码补全、Copilot Chat、Agent 模式、成熟生态。
安装
以 VS Code 为例:从市场搜索并安装官方 Copilot 扩展,重启编辑器,然后登录 GitHub 账户并通过命令面板授权。当状态栏显示"Copilot Enabled"时即配置完成。JetBrains 系列的操作方式相同。
# VS Code installation steps
1. Open VS Code → Extensions panel on the left (Cmd/Ctrl+Shift+X)
2. Search for "GitHub Copilot" → install the official extension
3. Restart VS Code
4. Cmd/Ctrl+Shift+P → type "GitHub Copilot: Sign In"
5. Browser redirects to GitHub for authorization → status bar shows "Copilot Enabled"
# Command-line install (optional)
code --install-extension GitHub.copilot
code --install-extension GitHub.copilot-chat需要 GitHub 账户和 Copilot 订阅(个人档有免费额度;学生和开源维护者可免费使用)。
基本用法
Copilot 的核心能力包括 Ghost Text 实时补全(按 Tab 接受)、Copilot Chat(Cmd/Ctrl+I)和内联编辑。在注释中用自然语言描述需求,Copilot 会生成相应代码;选中代码并让 Chat 解释、重构或添加测试。
# Write a comment in the editor and code is generated automatically
# Create a function: takes a date and returns how many days from today
def days_from_now(date_str):
# Copilot will autocomplete the implementation
...
# Copilot Chat (open with Cmd/Ctrl+I)
"Explain what this code does"
"Write unit tests for this function using pytest"
"Rewrite this callback style as async/await"
# Inline completion: press Tab to accept, Esc to dismiss按 Alt+] / Alt+[ 在补全建议之间循环;按 Cmd/Ctrl+Enter 查看完整建议列表。
技巧
Copilot 的补全质量高度依赖上下文:打开相关文件、写清晰的注释、使用规范的命名都能改善结果。Copilot Chat 支持 @workspace 引用整个工作区、#file 引用具体文件。2026 年的 Agent 模式可让你在 issue 中直接 @copilot,让它自主修复并提交 PR。注意在按量计费模式下,值得留意用量面板。
# Copilot Chat context references
"@workspace Where is the database connection initialized in this project?"
"#file:src/auth.ts Add input validation to this file"
# Summon the Agent in a GitHub issue
# In the comment box type: @copilot fix this issue
# Copilot will analyze, edit code, and submit a PR autonomously
# View usage
# github.com → Settings → Copilot → Usage提示:始终审查补全建议——AI 可能产生过时的 API 或不安全的代码;对于敏感项目,注意数据隐私设置。
Configuration
GitHub Copilot is configured through the IDE extension settings and your GitHub account. Subscription plans use usage-based billing, so the usage dashboard (github.com -> Settings -> Copilot -> Usage) matters. Model selection, Agent mode, and Code Review are toggled in the Copilot panel, and @workspace / #file references control context. Privacy settings govern whether snippets are sent to GitHub for suggestions.
# Model selection
# Copilot panel -> model dropdown -> pick GPT / Claude, etc.
# Agent mode (fix issues and open PRs)
# In a GitHub issue comment: @copilot fix this issue
# Context references in Copilot Chat
"@workspace Where is the DB connection initialized?"
"#file:src/auth.ts Add input validation"
# Privacy settings
# VS Code -> Settings -> GitHub Copilot -> enable/disable telemetry
# "Allow GitHub to use my code snippets for suggestions"
# View usage (usage-based billing)
# github.com -> Settings -> Copilot -> UsageUnder usage-based billing, keep an eye on the usage dashboard; Agent mode and long chats consume the most.
FAQ
Common questions cover subscription plans, student/free access, Agent mode, model selection, and data privacy. Copilot is free for verified students and maintainers of popular open-source projects. Agent mode lets you @copilot in an issue to get an autonomous fix and PR. Privacy settings control whether code snippets leave your machine.
Q: Is Copilot free?
A: There is a free tier with a monthly quota; verified students and
maintainers of popular open-source repos get it free.
Q: How does usage-based billing work?
A: Plans bill by usage (completions, chats, agent runs); monitor spend at
github.com -> Settings -> Copilot -> Usage.
Q: What is Agent mode?
A: Type @copilot in a GitHub issue and it analyzes, edits code, and opens
a PR autonomously.
Q: Can I choose the model?
A: Yes—pick from the model dropdown in the Copilot panel (GPT, Claude, etc.).
Q: Is my code sent to GitHub?
A: Snippets are sent for suggestions unless you disable it in privacy
settings; enterprise plans offer stricter data controls.Always review AI suggestions—models may produce outdated APIs or insecure code.
Ready to try GitHub Copilot?
Visit the official site for the latest version and full documentation.
Visit GitHub Copilot