GitHub Copilot 安装、使用方法详细全解数据来源GitHub 官方文档、GitHub Blog、VS Code 官方文档、社区讨论目录概述Copilot 核心功能全景支持的编辑器与环境定价方案与计费安装与配置指南使用方法详解Copilot CLI 完全使用指南Copilot Coding Agent云端代理ACP 协议与第三方集成最佳实践与注意事项与其他 AI 编程工具的对比1. 概述GitHub Copilot 是由 GitHub 与 OpenAI 联合开发的 AI 编程助手目前是全球使用最广泛的 AI 编码工具。它深度集成于多种主流 IDE原生构建于 GitHub 平台提供从代码补全到自主编码代理的全链路 AI 辅助。核心定位AI Pair ProgrammerAI 结对编程伙伴关键能力代码补全Inline suggestions对话式问答Copilot Chat多文件编辑Edits / Agent Mode终端命令生成Pull Request 摘要自主编码代理Coding Agent代码审查Code Review命令行助手CLI底层模型支持多模型选择包括 GPT-5 mini、Haiku 4.5、Claude含 Opus 级 premium 模型、Gemini 2.0 Flash、o3-mini 等。2. Copilot 核心功能全景2.1 辅助性功能Assistive Features— 同步协作功能说明Copilot Chat聊天界面可在 GitHub 网站、GitHub Mobile、支持的 IDE 和 Windows Terminal 中使用。支持 Skills 扩展Inline SuggestionsIDE 中的自动补全风格建议按行或整函数级别推荐Next Edit Suggestions预测你下一步可能编辑的位置并提前给出补全VS Code / Xcode / EclipsePR SummariesAI 自动生成的 Pull Request 变更摘要标注影响文件与审查重点GitHub Desktop自动根据项目变更生成 commit message 和描述2.2 代理性功能Agentic Features— 自主执行功能说明Copilot CLI命令行界面可在终端中使用 Copilot。支持添加功能、修复 bug、创建 PR。终端启动后可在 GitHub.com 或手机端继续同一会话Copilot Cloud Agent云端自主 AI 代理可研究仓库、创建实现计划、在分支上修改代码。可分配 GitHub Issue 给 Copilot 或直接要求它开 PR第三方 Coding Agents支持 Claude Code 和 Codex 等第三方代理与 Copilot Cloud Agent 并行使用公共预览Code ReviewAI 生成的代码审查建议帮助你编写更高质量的代码Agent ModeIDE 内允许 Copilot 在 IDE 中自主工作自动确定需要修改的文件、提出代码变更和终端命令供用户审批、迭代解决问题直到任务完成GitHub Spark使用自然语言提示构建和部署全栈应用与 GitHub 平台无缝集成公共预览2.3 自定义功能Custom Instructions自定义指令存储在仓库中copilot-instructions.md可定义项目的编码规范、约定和上下文Content Exclusion内容排除设置选择不将特定文件或目录发送给 AI 模型Skills可复用的指令集合扩展 Copilot Chat 的能力Model Selection在不同模型之间切换选择3. 支持的编辑器与环境GitHub Copilot 支持6 主流编辑器/IDE编辑器插件名称功能支持VS CodeGitHub Copilot全功能Chat、Completions、Agent Mode、Next Edit 等Visual StudioGitHub Copilot全功能含免费计划JetBrains IDEsGitHub Copilot全功能IntelliJ IDEA、PyCharm、WebStorm 等支持 Agent Mode 预览Neovimcopilot.vim / copilot.lua全功能XcodeGitHub Copilot全功能含 Next EditEclipseGitHub Copilot全功能含 Next EditGitHub.com 网页编辑器内置Chat、CompletionsGitHub Desktop内置Commit message 生成Windows Terminal内置Copilot CLI4. 定价方案与计费4.1 个人版计划截至 2026 年 6 月重大变更2026 年 6 月 1 日起Copilot 转为基于用量的计费模式Usage-Based Billing引入GitHub AI Credits概念。1 AI Credit $0.01 USD。计划月费AI Credits核心特性Free$0无2,000 次补全/月Haiku 4.5 GPT-5 miniCopilot CLIPro$10/月$15 总额Cloud Agent Code Review无限补全模型选择第三方代理Pro$39/月$70 总额Premium 模型Opus 等审计日志4 倍于 Pro 的额度Max$100/月$200 总额高量代理工作流优先访问新模型2.9 倍于 Pro 的额度注意Pro / Pro / Max 新计划注册暂时暂停GitHub 正在确保高质量体验现有用户可升级。学生免费获得 Pro 级功能。消耗规则代码补全Completions和 Next Edit 建议不消耗 CreditsChat 对话、Agent 模式、CLI 使用、Spaces、Spark消耗 CreditsCode Review 消耗 GitHub Actions 分钟数4.2 企业版计划计划月费/用户说明Copilot Business$19/用户/月团队管理、安全策略、使用分析Copilot Enterprise$39/用户/月企业级治理、审计日志、SSO、高级安全4.3 免费计划无需信用卡每月 2,000 次代码补全支持 Haiku 4.5、GPT-5 mini 等模型可访问 Copilot CLI经过验证的学生自动获得 Student 计划Pro 级功能5. 安装与配置指南5.1 前置条件GitHub 账户— 所有功能均需要Copilot 订阅— Free 及以上任一计划组织策略— 如果通过组织/企业获取 Copilot管理员需启用 CLI 策略5.2 VS Code 安装步骤步骤 1安装扩展1. 打开 VS Code 2. 点击左侧活动栏的扩展图标或 CtrlShiftX 3. 搜索 GitHub Copilot 4. 点击Install安装以下两个扩展 - GitHub Copilot主要扩展提供补全和 Agent Mode - GitHub Copilot Chat提供聊天功能步骤 2身份验证1. 安装后状态栏会出现 Copilot 图标 2. 将鼠标悬停在状态栏的 Copilot 图标上 3. 点击 Use AI Features 4. 选择登录方式 - 在浏览器中登录推荐 - 使用设备代码 - 使用 GitHub CLIgh 5. 在浏览器中完成 GitHub 账户登录和授权 6. VS Code 将自动检测到认证状态步骤 3验证安装1. 打开任意代码文件 2. 开始输入观察是否出现灰色补全建议 3. 按 CtrlShiftI 打开 Copilot Chat 面板 4. 输入一个问题如 explain this code步骤 4可选配置// .vscode/settings.json{// 设置默认模型github.copilot.chat.codeGeneration.model:gpt-5-mini,// 启用 Agent Modegithub.copilot.agent.enabled:true,// 自动接受建议editor.inlineSuggest.enabled:true,// Tab 接受建议editor.inlineSuggest.acceptOnTab:true,// 启用 Next Edit 建议github.copilot.nextEditSuggestions.enabled:true,// 终端命令审批模式github.copilot.agent.terminalApprovalMode:always}5.3 JetBrains IDE 安装步骤步骤 1安装插件1. 打开 JetBrains IDEIntelliJ IDEA / PyCharm / WebStorm 等 2. 进入 File → Settings → Plugins 3. 搜索 GitHub Copilot 4. 点击 Install 5. 重启 IDE步骤 2身份验证1. 在 JetBrains IDE 中登录 GitHub 账户 2. 进入 Settings → GitHub Copilot 3. 点击 Sign In 或使用 GitHub 插件中的身份验证 4. 完成浏览器中的授权流程步骤 3使用- Alt\\ 打开 Copilot Chat 面板 - 在编辑器中按 CtrlI 获取内联建议 - Agent Mode 为预览功能在 Chat 面板中启用5.4 Neovim 安装步骤-- 使用 lazy.nvim 安装return{{github/copilot.vim},-- 或使用 nvim-copilot.lua{zbirenbaum/copilot.lua,cmdCopilot,configfunction()require(copilot).setup({suggestion{enabledtrue,auto_triggertrue,keymap{acceptTab,accept_wordnil,accept_linenil,nextM-],prevM-[,dismissC-],},},})end,},}5.5 Copilot CLI 安装步骤方式一npm 安装跨平台推荐# 需要 Node.js 18npminstall-ggithub/copilot-cli# 验证安装copilot--version方式二HomebrewmacOS / Linux# macOSbrewinstallgithub/copilot/copilot# Linux (Homebrew Linux)brewinstallgithub/copilot/copilot方式三WinGetWindowswinget install GitHub.Copilot方式四安装脚本macOS / Linux# 下载并运行官方安装脚本curl-fsSLhttps://raw.githubusercontent.com/github/copilot-cli/main/install.sh|bash方式五手动下载 Release 二进制# 从 GitHub Releases 页面下载对应平台的二进制文件# https://github.com/github/copilot-cli/releases# 解压并复制到 PATH 中5.6 Copilot CLI 身份验证# 方式 1通过浏览器认证copilot auth login# 方式 2使用 GitHub CLIgh的认证# 如果已安装 gh 并登录CLI 会自动使用 gh 的凭据gh auth login copilot# 直接使用自动继承 gh 认证# 方式 3使用 PATPersonal Access Token# 设置环境变量exportGITHUB_TOKENyour-token-here# 或写入配置文件copilot configsettokenyour-token-here5.7 Copilot CLI 配置配置文件位置~/.config/github-copilot/copilot-cli.json{model:gpt-5-mini,// 默认模型voice:{enabled:true// 启用语音输入},auth:{method:github// 认证方式},tools:{browser:ask,// 浏览器工具审批模式terminal:ask,// 终端命令审批模式fileEdit:ask,// 文件编辑审批模式fileWrite:ask// 文件写入审批模式}}工具审批模式选项always— 始终允许不提示ask— 每次使用前询问never— 始终拒绝常用配置命令# 设置默认模型copilot configsetmodelgpt-5-mini# 设置认证 tokencopilot configsettokenghp_xxxxx# 查看当前配置copilot config list# 重置配置copilot configunsetkey6. 使用方法详解6.1 代码补全Completions基本使用在编辑器中输入代码Copilot 会自动显示灰色建议按Tab接受建议按Esc或Right Arrow部分接受按CtrlZ撤销快捷键VS CodeTab — 接受完整建议 CtrlEnter — 查看所有建议变体 Alt[ — 上一个建议 Alt] — 下一个建议提示使用注释作为提示引导补全方向// 创建一个 REST API 端点补全基于当前文件 打开的相关文件 仓库上下文在 Pro 及以上计划中补全是无限的且不消耗 Credits6.2 Next Edit Suggestions下一步编辑建议说明预测你下一步将编辑的位置可能在当前文件的其他位置或另一个文件中并提前生成建议。启用方式VS Code{github.copilot.nextEditSuggestions.enabled:true}特点在编辑器边缘显示蓝色标记指示建议编辑的位置点击蓝色标记或按快捷键跳转到建议位置适用于 VS Code、Xcode、Eclipse6.3 Copilot Chat打开方式VS Code:CtrlShiftI或点击活动栏的 Chat 图标JetBrains:Alt\网页版: GitHub 上的 Copilot 标签页基本用法workspace — 引入工作区上下文 terminal — 使用终端上下文 github — 引入 GitHub 上下文 #file:path/to/file — 引用特定文件常用命令/terminal command — 在聊天中运行终端命令 /new — 开始新的对话 /workspace — 基于整个工作区上下文回答问题对话示例Q: Explain this function 选中函数后提问 Q: workspace What is the project architecture? Q: terminal list the 5 largest files in this workspace Q: #file:src/main.py refactor this for better performance6.4 Agent ModeIDE 内代理模式什么是 Agent ModeCopilot 可以自主在 IDE 中工作确定需要修改的文件、提出代码变更和终端命令供审批、迭代修复问题直到任务完成。启用与使用VS Code 中启用在 Chat 面板中点击右上角的 Agent Mode 开关或在 Chat 输入框中直接描述任务工作流程用户在 Chat 中输入自然语言任务描述 ↓ Copilot分析任务确定需要修改的文件 ↓ Copilot提出代码变更和终端命令 ↓ 用户审批Allow/Deny 每次操作或全局 Allow All ↓ Copilot执行并验证 ↓ Copilot如遇错误自动迭代修复 ↓ 完成任务完成用户审查结果审批控制终端命令可设为always自动、ask询问、never拒绝文件编辑可设为always、ask、never全局审批允许全局允许所有操作Global Auto Approve典型任务示例Add input validation to the login API endpoint Refactor the database queries to use async/await Create unit tests for the UserService class Fix the bugs shown in the test output below6.5 Copilot Edits说明多文件编辑功能允许 Copilot 同时修改多个文件。使用方法1. 在 Copilot Chat 中输入编辑请求 2. Copilot 显示将要做的所有变更预览 3. 用户审查后点击 Apply 应用所有变更示例提示Rename the getUser function to fetchUserProfile across all files Update all API calls to use the new v2 endpoint format Add TypeScript types to all JavaScript files in the src directory6.6 PR 摘要自动触发当创建 Pull Request 时Copilot 自动生成变更摘要摘要包括变更概述、影响文件列表、审查重点手动生成在 PR 页面点击 Copilot 按钮或在 PR 描述中使用/copilot summarize6.7 自定义指令Custom Instructions仓库级指令在项目根目录创建copilot-instructions.md# Project Instructions ## Tech Stack - React 18 with TypeScript - Tailwind CSS for styling - Zustand for state management ## Coding Standards - Use functional components with hooks - Prefer named exports over default exports - Write JSDoc comments for all public functions - Error handling: use custom Error classes, never throw raw strings ## Testing - Use Vitest for unit tests - Use Playwright for E2E tests - Test files go in __tests__ directory ## Conventions - API responses follow { data, error, meta } format - Environment variables prefixed with APP_效果Copilot 在生成代码和回答问题时将遵循这些指令。7. Copilot CLI 完全使用指南Copilot CLI 是一个命令行工具让你直接在终端中使用 Copilot。可以在 CLI 中开始任务然后在 GitHub.com 或手机上的同一会话中继续。7.1 启动与基本使用启动交互式会话# 基本启动进入对话模式copilot# 带初始提示启动copilotexplain this codebase# 一次性命令copilotlist all Python files in the project退出会话CtrlC — 退出当前会话 /quit — 退出 /exit — 退出7.2 核心命令解释命令explain# 解释一个命令的作用copilot explainsudo rm -rf /tmp/old_datacopilot explaindocker build -t myapp . docker push myapp# 解释 git 命令copilot explaingit rebase -i HEAD~5建议命令suggest# 让 Copilot 建议一个命令copilot suggestfind all files larger than 100MBcopilot suggestrestart nginx servicecopilot suggestcompress all .log files in /var/log配置config# 查看所有配置copilot config list# 设置配置项copilot configsetmodelgpt-5-minicopilot configsettokenghp_xxx# 删除配置项copilot configunsetmodel7.3 对话模式开始对话copilot在对话中可以做# 代码相关 Create a Python script to parse JSON logs Write a bash function to monitor disk usage Generate a Dockerfile for this Node.js project # 理解代码 Explain what this code does 粘贴代码 What is the architecture of this project? Find potential bugs in src/auth.py # Git 操作 Show me the diff for branch feature-x Create a commit message for my staged changes Review the latest pull request # 系统管理 How do I set up a firewall rule for port 8080? Write a systemd service file for my app7.4 交互式命令工具在 CLI 中直接使用代理功能文件操作用户: Create a new Python file called utils.py with helper functions Copilot: 创建文件并显示内容预览 用户: [Approve] 确认或修改终端命令执行用户: Run tests in the tests directory Copilot: 提出运行 pytest tests/ 命令 用户: [Approve] 确认后执行代码修改用户: Refactor the login function to use async/await Copilot: 显示 diff 预览 用户: [Approve] 应用变更7.5 委派任务Delegation# 在 CLI 中委派任务给 CopilotcopilotAdd error handling to all API endpoints and create a PR# Copilot 会# 1. 分析代码库# 2. 确定需要修改的文件# 3. 逐个文件进行修改# 4. 运行测试# 5. 创建分支和 PR7.6 浏览 GitHub 资源# 浏览 IssuescopilotShow me open issues with the bug label# 浏览 PRscopilotList my open pull requestscopilotReview PR #123# 浏览 GistscopilotShow me my recent gists7.7 语音输入启用在配置中{voice:{enabled:true}}使用在 Copilot CLI 对话中按麦克风图标或语音快捷键 直接用语音说出你的请求 Copilot 将语音转录为文本并处理7.8 连接到 VS Code# 从 CLI 连接到 VS Code 工作区copilot connect-vscode# 效果# - CLI 会话与 VS Code 共享上下文# - 在 CLI 中的操作反映在 VS Code 中# - 可以查看 VS Code 中打开的文件和编辑器状态7.9 回滚变更# 如果在 CLI 会话中做了不满意的变更/rollback# 回滚到最后一次变更/rollback--last# 回滚到特定点/rollback--totimestamp7.10 调用自定义代理# 在 CLI 中调用自定义 agentcopilot agent runmy-custom-agent# 或者在对话中使用/slash agentagent-nametask7.11 引导代理Steering在 CLI 会话中实时引导 Copilot 的行为# 修正方向 Actually, lets use SQLite instead of PostgreSQL Focus on performance optimization, not new features Stop and explain what youre doing # 请求详细信息 Show me the full diff before applying Explain why you chose this approach # 暂停和恢复 CtrlC — 暂停当前操作 /resume — 恢复7.12 远程引导会话# 在终端启动会话copilotImplement feature X# 在手机或其他设备上继续# 访问 GitHub.com找到运行中的 Copilot 会话# 添加评论引导 Copilot# 在手机上审查和批准变更7.13 代理代码审查# 在 CLI 中请求代码审查copilotReview my changes for security issuescopilotReview the code in src/ for potential bugs7.14 管理 Pull Requests# 在 CLI 中创建 PRcopilotCreate a PR for my changes# 在 CLI 中管理 PRcopilotList all my open PRscopilotUpdate PR #42 descriptioncopilotMerge PR #42 with squash7.15 加速任务完成# 使用并行工具调用加速copilot--parallelRun tests, lint code, and check types simultaneously# 使用流式输出copilot--streamGenerate documentation for all API endpoints7.16 使用会话数据# 查看当前会话的用量/usage# 查看会话历史/history# 导出会话/export session.md8. Copilot Coding Agent云端代理8.1 概述GitHub Copilot Coding Agent 是一个异步 AI 代理作为你的异步 AI 队友工作。它在 GitHub 的云端开发环境中工作可以研究代码仓库创建实现计划在分支上进行代码变更创建 Draft Pull Request自主迭代直到任务完成8.2 使用方式方式 1从 GitHub Issue 启动1. 在 GitHub 仓库中打开一个 Issue 2. 在 Assignees 下拉菜单中选择 Copilot 3. Copilot 开始分析 Issue 并在后台工作方式 2从 Agents 面板启动1. 在仓库页面点击 Agents 标签 2. 输入任务描述 3. Copilot 开始工作方式 3从 Copilot Chat 启动在 Chat 中: Open a pull request that adds feature X方式 4使用 CLIghprcreate--agentImplement feature X方式 5使用 APIcurl-XPOST https://api.github.com/repos/owner/repo/agents/sessions\-HAuthorization: Bearer$GITHUB_TOKEN\-d{task: Implement feature X}8.3 工作流程1. 分配任务给 Copilot ↓ 2. Copilot 研究仓库理解代码库 ↓ 3. Copilot 创建实现计划 ↓ 4. Copilot 创建新分支 ↓ 5. Copilot 在分支上进行代码变更 ↓ 6. Copilot 创建 Draft PR ↓ 7. 用户审查 diff ↓ 8. 用户可以在 PR 评论中迭代also add error handling ↓ 9. 用户合并 PR 或请求更多修改8.4 安全限制代理在 GitHub 的沙箱环境中运行不能直接访问本地文件系统只能修改指定仓库的文件PR 合并需要人工批准8.5 第三方代理支持以下第三方代理公共预览Claude Code— Anthropic 的编程代理Codex— OpenAI 的编程代理9. ACP 协议与第三方集成9.1 什么是 ACPACPAgent Communication Protocol是 GitHub 定义的代理通信协议类似于语言服务器协议LSP。它将 AI 代理能力与 IDE 解耦允许任何支持 ACP 的客户端使用 Copilot 作为后端代理。9.2 ACP Server 模式# 将 Copilot CLI 作为 ACP Server 启动copilot--acp# 两种模式# stdio 模式默认— 通过标准输入输出通信copilot--acp# TCP 模式 — 通过网络端口通信copilot--acp--tcp--port189999.3 应用场景# 在 Zed 编辑器中使用 Copilot # Zed 支持 ACP 协议可以连接 Copilot CLI 作为后端 # 在自定义自动化脚本中使用 Copilot # 通过 ACP 协议发送任务接收结果 # 集成到 CI/CD 流水线 # 使用 ACP Server 模式在构建过程中调用 Copilot10. 最佳实践与注意事项10.1 使用最佳实践提供清晰的上下文在 Chat 中使用workspace、file等引入相关上下文使用自定义指令在项目根目录放置copilot-instructions.md从小任务开始先用小任务测试再逐步加大复杂度审查所有变更即使信任 AI也始终审查生成的代码使用 Agent Mode 时设置合理的审批策略建议终端命令使用ask模式管理 Credits 使用了解哪些操作消耗 Credits优先使用不消耗 Credits 的补全功能10.2 提示工程技巧❌ 差: Fix this ✅ 好: Fix the null pointer exception in line 45 of UserService.java. The issue is that user can be null when fetchById returns empty. ❌ 差: Add tests ✅ 好: Write unit tests for the calculateTotal() function in src/pricing.ts. Cover these edge cases: empty cart, discounted items, and currency conversion errors. ❌ 差: Make it faster ✅ 好: Optimize the database query in getUserOrders() — its currently N1. Use eager loading or a JOIN to reduce queries from O(n) to O(1).10.3 安全注意事项启用 Content Exclusion 排除敏感文件.env、密钥文件等在 Agent Mode 中将终端命令设为ask模式不要将生产环境密钥粘贴到 Chat 中使用企业版时配置安全策略和审计日志10.4 Credits 管理技巧代码补全不消耗 Credits — 充分利用Chat 对话尽量具体减少来回次数Agent Mode 使用复杂任务时消耗较多 — 确保任务描述准确定期检查用量/usageCLI或 GitHub 设置页面Free 用户的 2,000 次补全通常足够日常使用11. 与其他 AI 编程工具的对比11.1 Copilot vs Cursor维度GitHub CopilotCursorIDE 支持6 IDEVS Code, JetBrains, Neovim, Xcode 等仅 Cursor基于 VS Code 的独立编辑器多文件编辑支持Edits / Agent Mode支持内置 Agent价格Free / $10-100/月$20-40/月GitHub 集成原生PR、Issues、Code Review有限模型选择多模型GPT, Claude, Gemini内置模型选择SWE-bench 得分56%51.7%11.2 Copilot vs Windsurf维度GitHub CopilotWindsurfIDE 支持6 IDE仅 Windsurf代理模式支持Agent Mode Cloud Agent支持FlowsCLI支持Copilot CLI有限价格从 Free 开始$20/月起11.3 选择建议需要多 IDE 支持→ Copilot无可争议的最佳选择深度 GitHub 工作流→ Copilot原生集成 PR、Issues、Code Review想要单一编辑器深度优化→ Cursor / Windsurf预算有限→ Copilot Free2000 次补全/月 CLI需要 ACP 协议集成→ Copilot CLI支持 ACP Server 模式附录快速参考A. 常用快捷键操作VS CodeJetBrainsNeovim打开 ChatCtrlShiftIAlt\见配置接受补全TabTabTab查看建议变体CtrlEnter——上一个建议Alt[——下一个建议Alt]——解释选中代码CtrlICtrlI—生成文档—CtrlI—B. 配置文件位置项目路径Copilot CLI 配置~/.config/github-copilot/Copilot CLI 会话~/.config/github-copilot/sessions/VS Code 设置.vscode/settings.json仓库级指令copilot-instructions.md项目根目录内容排除规则.github/copilot-chat.mdC. 官方文档链接GitHub Copilot 主页: https://github.com/features/copilot功能概览: https://docs.github.com/en/copilot/get-started/features快速开始: https://docs.github.com/en/copilot/get-started/quickstart定价方案: https://github.com/features/copilot/plansCopilot CLI 文档: https://docs.github.com/en/copilot/how-tos/copilot-cliACP Server 文档: https://docs.github.com/en/copilot/reference/copilot-cli-reference/acp-serverCloud Agent 文档: https://docs.github.com/copilot/concepts/agents/coding-agent/about-coding-agentVS Code 设置: https://code.visualstudio.com/docs/copilot/setupJetBrains 插件: https://plugins.jetbrains.com/plugin/17718-github-copilot–your-ai-pair-programmer
GitHub Copilot 安装、使用方法详细全解
发布时间:2026/6/7 14:16:25
GitHub Copilot 安装、使用方法详细全解数据来源GitHub 官方文档、GitHub Blog、VS Code 官方文档、社区讨论目录概述Copilot 核心功能全景支持的编辑器与环境定价方案与计费安装与配置指南使用方法详解Copilot CLI 完全使用指南Copilot Coding Agent云端代理ACP 协议与第三方集成最佳实践与注意事项与其他 AI 编程工具的对比1. 概述GitHub Copilot 是由 GitHub 与 OpenAI 联合开发的 AI 编程助手目前是全球使用最广泛的 AI 编码工具。它深度集成于多种主流 IDE原生构建于 GitHub 平台提供从代码补全到自主编码代理的全链路 AI 辅助。核心定位AI Pair ProgrammerAI 结对编程伙伴关键能力代码补全Inline suggestions对话式问答Copilot Chat多文件编辑Edits / Agent Mode终端命令生成Pull Request 摘要自主编码代理Coding Agent代码审查Code Review命令行助手CLI底层模型支持多模型选择包括 GPT-5 mini、Haiku 4.5、Claude含 Opus 级 premium 模型、Gemini 2.0 Flash、o3-mini 等。2. Copilot 核心功能全景2.1 辅助性功能Assistive Features— 同步协作功能说明Copilot Chat聊天界面可在 GitHub 网站、GitHub Mobile、支持的 IDE 和 Windows Terminal 中使用。支持 Skills 扩展Inline SuggestionsIDE 中的自动补全风格建议按行或整函数级别推荐Next Edit Suggestions预测你下一步可能编辑的位置并提前给出补全VS Code / Xcode / EclipsePR SummariesAI 自动生成的 Pull Request 变更摘要标注影响文件与审查重点GitHub Desktop自动根据项目变更生成 commit message 和描述2.2 代理性功能Agentic Features— 自主执行功能说明Copilot CLI命令行界面可在终端中使用 Copilot。支持添加功能、修复 bug、创建 PR。终端启动后可在 GitHub.com 或手机端继续同一会话Copilot Cloud Agent云端自主 AI 代理可研究仓库、创建实现计划、在分支上修改代码。可分配 GitHub Issue 给 Copilot 或直接要求它开 PR第三方 Coding Agents支持 Claude Code 和 Codex 等第三方代理与 Copilot Cloud Agent 并行使用公共预览Code ReviewAI 生成的代码审查建议帮助你编写更高质量的代码Agent ModeIDE 内允许 Copilot 在 IDE 中自主工作自动确定需要修改的文件、提出代码变更和终端命令供用户审批、迭代解决问题直到任务完成GitHub Spark使用自然语言提示构建和部署全栈应用与 GitHub 平台无缝集成公共预览2.3 自定义功能Custom Instructions自定义指令存储在仓库中copilot-instructions.md可定义项目的编码规范、约定和上下文Content Exclusion内容排除设置选择不将特定文件或目录发送给 AI 模型Skills可复用的指令集合扩展 Copilot Chat 的能力Model Selection在不同模型之间切换选择3. 支持的编辑器与环境GitHub Copilot 支持6 主流编辑器/IDE编辑器插件名称功能支持VS CodeGitHub Copilot全功能Chat、Completions、Agent Mode、Next Edit 等Visual StudioGitHub Copilot全功能含免费计划JetBrains IDEsGitHub Copilot全功能IntelliJ IDEA、PyCharm、WebStorm 等支持 Agent Mode 预览Neovimcopilot.vim / copilot.lua全功能XcodeGitHub Copilot全功能含 Next EditEclipseGitHub Copilot全功能含 Next EditGitHub.com 网页编辑器内置Chat、CompletionsGitHub Desktop内置Commit message 生成Windows Terminal内置Copilot CLI4. 定价方案与计费4.1 个人版计划截至 2026 年 6 月重大变更2026 年 6 月 1 日起Copilot 转为基于用量的计费模式Usage-Based Billing引入GitHub AI Credits概念。1 AI Credit $0.01 USD。计划月费AI Credits核心特性Free$0无2,000 次补全/月Haiku 4.5 GPT-5 miniCopilot CLIPro$10/月$15 总额Cloud Agent Code Review无限补全模型选择第三方代理Pro$39/月$70 总额Premium 模型Opus 等审计日志4 倍于 Pro 的额度Max$100/月$200 总额高量代理工作流优先访问新模型2.9 倍于 Pro 的额度注意Pro / Pro / Max 新计划注册暂时暂停GitHub 正在确保高质量体验现有用户可升级。学生免费获得 Pro 级功能。消耗规则代码补全Completions和 Next Edit 建议不消耗 CreditsChat 对话、Agent 模式、CLI 使用、Spaces、Spark消耗 CreditsCode Review 消耗 GitHub Actions 分钟数4.2 企业版计划计划月费/用户说明Copilot Business$19/用户/月团队管理、安全策略、使用分析Copilot Enterprise$39/用户/月企业级治理、审计日志、SSO、高级安全4.3 免费计划无需信用卡每月 2,000 次代码补全支持 Haiku 4.5、GPT-5 mini 等模型可访问 Copilot CLI经过验证的学生自动获得 Student 计划Pro 级功能5. 安装与配置指南5.1 前置条件GitHub 账户— 所有功能均需要Copilot 订阅— Free 及以上任一计划组织策略— 如果通过组织/企业获取 Copilot管理员需启用 CLI 策略5.2 VS Code 安装步骤步骤 1安装扩展1. 打开 VS Code 2. 点击左侧活动栏的扩展图标或 CtrlShiftX 3. 搜索 GitHub Copilot 4. 点击Install安装以下两个扩展 - GitHub Copilot主要扩展提供补全和 Agent Mode - GitHub Copilot Chat提供聊天功能步骤 2身份验证1. 安装后状态栏会出现 Copilot 图标 2. 将鼠标悬停在状态栏的 Copilot 图标上 3. 点击 Use AI Features 4. 选择登录方式 - 在浏览器中登录推荐 - 使用设备代码 - 使用 GitHub CLIgh 5. 在浏览器中完成 GitHub 账户登录和授权 6. VS Code 将自动检测到认证状态步骤 3验证安装1. 打开任意代码文件 2. 开始输入观察是否出现灰色补全建议 3. 按 CtrlShiftI 打开 Copilot Chat 面板 4. 输入一个问题如 explain this code步骤 4可选配置// .vscode/settings.json{// 设置默认模型github.copilot.chat.codeGeneration.model:gpt-5-mini,// 启用 Agent Modegithub.copilot.agent.enabled:true,// 自动接受建议editor.inlineSuggest.enabled:true,// Tab 接受建议editor.inlineSuggest.acceptOnTab:true,// 启用 Next Edit 建议github.copilot.nextEditSuggestions.enabled:true,// 终端命令审批模式github.copilot.agent.terminalApprovalMode:always}5.3 JetBrains IDE 安装步骤步骤 1安装插件1. 打开 JetBrains IDEIntelliJ IDEA / PyCharm / WebStorm 等 2. 进入 File → Settings → Plugins 3. 搜索 GitHub Copilot 4. 点击 Install 5. 重启 IDE步骤 2身份验证1. 在 JetBrains IDE 中登录 GitHub 账户 2. 进入 Settings → GitHub Copilot 3. 点击 Sign In 或使用 GitHub 插件中的身份验证 4. 完成浏览器中的授权流程步骤 3使用- Alt\\ 打开 Copilot Chat 面板 - 在编辑器中按 CtrlI 获取内联建议 - Agent Mode 为预览功能在 Chat 面板中启用5.4 Neovim 安装步骤-- 使用 lazy.nvim 安装return{{github/copilot.vim},-- 或使用 nvim-copilot.lua{zbirenbaum/copilot.lua,cmdCopilot,configfunction()require(copilot).setup({suggestion{enabledtrue,auto_triggertrue,keymap{acceptTab,accept_wordnil,accept_linenil,nextM-],prevM-[,dismissC-],},},})end,},}5.5 Copilot CLI 安装步骤方式一npm 安装跨平台推荐# 需要 Node.js 18npminstall-ggithub/copilot-cli# 验证安装copilot--version方式二HomebrewmacOS / Linux# macOSbrewinstallgithub/copilot/copilot# Linux (Homebrew Linux)brewinstallgithub/copilot/copilot方式三WinGetWindowswinget install GitHub.Copilot方式四安装脚本macOS / Linux# 下载并运行官方安装脚本curl-fsSLhttps://raw.githubusercontent.com/github/copilot-cli/main/install.sh|bash方式五手动下载 Release 二进制# 从 GitHub Releases 页面下载对应平台的二进制文件# https://github.com/github/copilot-cli/releases# 解压并复制到 PATH 中5.6 Copilot CLI 身份验证# 方式 1通过浏览器认证copilot auth login# 方式 2使用 GitHub CLIgh的认证# 如果已安装 gh 并登录CLI 会自动使用 gh 的凭据gh auth login copilot# 直接使用自动继承 gh 认证# 方式 3使用 PATPersonal Access Token# 设置环境变量exportGITHUB_TOKENyour-token-here# 或写入配置文件copilot configsettokenyour-token-here5.7 Copilot CLI 配置配置文件位置~/.config/github-copilot/copilot-cli.json{model:gpt-5-mini,// 默认模型voice:{enabled:true// 启用语音输入},auth:{method:github// 认证方式},tools:{browser:ask,// 浏览器工具审批模式terminal:ask,// 终端命令审批模式fileEdit:ask,// 文件编辑审批模式fileWrite:ask// 文件写入审批模式}}工具审批模式选项always— 始终允许不提示ask— 每次使用前询问never— 始终拒绝常用配置命令# 设置默认模型copilot configsetmodelgpt-5-mini# 设置认证 tokencopilot configsettokenghp_xxxxx# 查看当前配置copilot config list# 重置配置copilot configunsetkey6. 使用方法详解6.1 代码补全Completions基本使用在编辑器中输入代码Copilot 会自动显示灰色建议按Tab接受建议按Esc或Right Arrow部分接受按CtrlZ撤销快捷键VS CodeTab — 接受完整建议 CtrlEnter — 查看所有建议变体 Alt[ — 上一个建议 Alt] — 下一个建议提示使用注释作为提示引导补全方向// 创建一个 REST API 端点补全基于当前文件 打开的相关文件 仓库上下文在 Pro 及以上计划中补全是无限的且不消耗 Credits6.2 Next Edit Suggestions下一步编辑建议说明预测你下一步将编辑的位置可能在当前文件的其他位置或另一个文件中并提前生成建议。启用方式VS Code{github.copilot.nextEditSuggestions.enabled:true}特点在编辑器边缘显示蓝色标记指示建议编辑的位置点击蓝色标记或按快捷键跳转到建议位置适用于 VS Code、Xcode、Eclipse6.3 Copilot Chat打开方式VS Code:CtrlShiftI或点击活动栏的 Chat 图标JetBrains:Alt\网页版: GitHub 上的 Copilot 标签页基本用法workspace — 引入工作区上下文 terminal — 使用终端上下文 github — 引入 GitHub 上下文 #file:path/to/file — 引用特定文件常用命令/terminal command — 在聊天中运行终端命令 /new — 开始新的对话 /workspace — 基于整个工作区上下文回答问题对话示例Q: Explain this function 选中函数后提问 Q: workspace What is the project architecture? Q: terminal list the 5 largest files in this workspace Q: #file:src/main.py refactor this for better performance6.4 Agent ModeIDE 内代理模式什么是 Agent ModeCopilot 可以自主在 IDE 中工作确定需要修改的文件、提出代码变更和终端命令供审批、迭代修复问题直到任务完成。启用与使用VS Code 中启用在 Chat 面板中点击右上角的 Agent Mode 开关或在 Chat 输入框中直接描述任务工作流程用户在 Chat 中输入自然语言任务描述 ↓ Copilot分析任务确定需要修改的文件 ↓ Copilot提出代码变更和终端命令 ↓ 用户审批Allow/Deny 每次操作或全局 Allow All ↓ Copilot执行并验证 ↓ Copilot如遇错误自动迭代修复 ↓ 完成任务完成用户审查结果审批控制终端命令可设为always自动、ask询问、never拒绝文件编辑可设为always、ask、never全局审批允许全局允许所有操作Global Auto Approve典型任务示例Add input validation to the login API endpoint Refactor the database queries to use async/await Create unit tests for the UserService class Fix the bugs shown in the test output below6.5 Copilot Edits说明多文件编辑功能允许 Copilot 同时修改多个文件。使用方法1. 在 Copilot Chat 中输入编辑请求 2. Copilot 显示将要做的所有变更预览 3. 用户审查后点击 Apply 应用所有变更示例提示Rename the getUser function to fetchUserProfile across all files Update all API calls to use the new v2 endpoint format Add TypeScript types to all JavaScript files in the src directory6.6 PR 摘要自动触发当创建 Pull Request 时Copilot 自动生成变更摘要摘要包括变更概述、影响文件列表、审查重点手动生成在 PR 页面点击 Copilot 按钮或在 PR 描述中使用/copilot summarize6.7 自定义指令Custom Instructions仓库级指令在项目根目录创建copilot-instructions.md# Project Instructions ## Tech Stack - React 18 with TypeScript - Tailwind CSS for styling - Zustand for state management ## Coding Standards - Use functional components with hooks - Prefer named exports over default exports - Write JSDoc comments for all public functions - Error handling: use custom Error classes, never throw raw strings ## Testing - Use Vitest for unit tests - Use Playwright for E2E tests - Test files go in __tests__ directory ## Conventions - API responses follow { data, error, meta } format - Environment variables prefixed with APP_效果Copilot 在生成代码和回答问题时将遵循这些指令。7. Copilot CLI 完全使用指南Copilot CLI 是一个命令行工具让你直接在终端中使用 Copilot。可以在 CLI 中开始任务然后在 GitHub.com 或手机上的同一会话中继续。7.1 启动与基本使用启动交互式会话# 基本启动进入对话模式copilot# 带初始提示启动copilotexplain this codebase# 一次性命令copilotlist all Python files in the project退出会话CtrlC — 退出当前会话 /quit — 退出 /exit — 退出7.2 核心命令解释命令explain# 解释一个命令的作用copilot explainsudo rm -rf /tmp/old_datacopilot explaindocker build -t myapp . docker push myapp# 解释 git 命令copilot explaingit rebase -i HEAD~5建议命令suggest# 让 Copilot 建议一个命令copilot suggestfind all files larger than 100MBcopilot suggestrestart nginx servicecopilot suggestcompress all .log files in /var/log配置config# 查看所有配置copilot config list# 设置配置项copilot configsetmodelgpt-5-minicopilot configsettokenghp_xxx# 删除配置项copilot configunsetmodel7.3 对话模式开始对话copilot在对话中可以做# 代码相关 Create a Python script to parse JSON logs Write a bash function to monitor disk usage Generate a Dockerfile for this Node.js project # 理解代码 Explain what this code does 粘贴代码 What is the architecture of this project? Find potential bugs in src/auth.py # Git 操作 Show me the diff for branch feature-x Create a commit message for my staged changes Review the latest pull request # 系统管理 How do I set up a firewall rule for port 8080? Write a systemd service file for my app7.4 交互式命令工具在 CLI 中直接使用代理功能文件操作用户: Create a new Python file called utils.py with helper functions Copilot: 创建文件并显示内容预览 用户: [Approve] 确认或修改终端命令执行用户: Run tests in the tests directory Copilot: 提出运行 pytest tests/ 命令 用户: [Approve] 确认后执行代码修改用户: Refactor the login function to use async/await Copilot: 显示 diff 预览 用户: [Approve] 应用变更7.5 委派任务Delegation# 在 CLI 中委派任务给 CopilotcopilotAdd error handling to all API endpoints and create a PR# Copilot 会# 1. 分析代码库# 2. 确定需要修改的文件# 3. 逐个文件进行修改# 4. 运行测试# 5. 创建分支和 PR7.6 浏览 GitHub 资源# 浏览 IssuescopilotShow me open issues with the bug label# 浏览 PRscopilotList my open pull requestscopilotReview PR #123# 浏览 GistscopilotShow me my recent gists7.7 语音输入启用在配置中{voice:{enabled:true}}使用在 Copilot CLI 对话中按麦克风图标或语音快捷键 直接用语音说出你的请求 Copilot 将语音转录为文本并处理7.8 连接到 VS Code# 从 CLI 连接到 VS Code 工作区copilot connect-vscode# 效果# - CLI 会话与 VS Code 共享上下文# - 在 CLI 中的操作反映在 VS Code 中# - 可以查看 VS Code 中打开的文件和编辑器状态7.9 回滚变更# 如果在 CLI 会话中做了不满意的变更/rollback# 回滚到最后一次变更/rollback--last# 回滚到特定点/rollback--totimestamp7.10 调用自定义代理# 在 CLI 中调用自定义 agentcopilot agent runmy-custom-agent# 或者在对话中使用/slash agentagent-nametask7.11 引导代理Steering在 CLI 会话中实时引导 Copilot 的行为# 修正方向 Actually, lets use SQLite instead of PostgreSQL Focus on performance optimization, not new features Stop and explain what youre doing # 请求详细信息 Show me the full diff before applying Explain why you chose this approach # 暂停和恢复 CtrlC — 暂停当前操作 /resume — 恢复7.12 远程引导会话# 在终端启动会话copilotImplement feature X# 在手机或其他设备上继续# 访问 GitHub.com找到运行中的 Copilot 会话# 添加评论引导 Copilot# 在手机上审查和批准变更7.13 代理代码审查# 在 CLI 中请求代码审查copilotReview my changes for security issuescopilotReview the code in src/ for potential bugs7.14 管理 Pull Requests# 在 CLI 中创建 PRcopilotCreate a PR for my changes# 在 CLI 中管理 PRcopilotList all my open PRscopilotUpdate PR #42 descriptioncopilotMerge PR #42 with squash7.15 加速任务完成# 使用并行工具调用加速copilot--parallelRun tests, lint code, and check types simultaneously# 使用流式输出copilot--streamGenerate documentation for all API endpoints7.16 使用会话数据# 查看当前会话的用量/usage# 查看会话历史/history# 导出会话/export session.md8. Copilot Coding Agent云端代理8.1 概述GitHub Copilot Coding Agent 是一个异步 AI 代理作为你的异步 AI 队友工作。它在 GitHub 的云端开发环境中工作可以研究代码仓库创建实现计划在分支上进行代码变更创建 Draft Pull Request自主迭代直到任务完成8.2 使用方式方式 1从 GitHub Issue 启动1. 在 GitHub 仓库中打开一个 Issue 2. 在 Assignees 下拉菜单中选择 Copilot 3. Copilot 开始分析 Issue 并在后台工作方式 2从 Agents 面板启动1. 在仓库页面点击 Agents 标签 2. 输入任务描述 3. Copilot 开始工作方式 3从 Copilot Chat 启动在 Chat 中: Open a pull request that adds feature X方式 4使用 CLIghprcreate--agentImplement feature X方式 5使用 APIcurl-XPOST https://api.github.com/repos/owner/repo/agents/sessions\-HAuthorization: Bearer$GITHUB_TOKEN\-d{task: Implement feature X}8.3 工作流程1. 分配任务给 Copilot ↓ 2. Copilot 研究仓库理解代码库 ↓ 3. Copilot 创建实现计划 ↓ 4. Copilot 创建新分支 ↓ 5. Copilot 在分支上进行代码变更 ↓ 6. Copilot 创建 Draft PR ↓ 7. 用户审查 diff ↓ 8. 用户可以在 PR 评论中迭代also add error handling ↓ 9. 用户合并 PR 或请求更多修改8.4 安全限制代理在 GitHub 的沙箱环境中运行不能直接访问本地文件系统只能修改指定仓库的文件PR 合并需要人工批准8.5 第三方代理支持以下第三方代理公共预览Claude Code— Anthropic 的编程代理Codex— OpenAI 的编程代理9. ACP 协议与第三方集成9.1 什么是 ACPACPAgent Communication Protocol是 GitHub 定义的代理通信协议类似于语言服务器协议LSP。它将 AI 代理能力与 IDE 解耦允许任何支持 ACP 的客户端使用 Copilot 作为后端代理。9.2 ACP Server 模式# 将 Copilot CLI 作为 ACP Server 启动copilot--acp# 两种模式# stdio 模式默认— 通过标准输入输出通信copilot--acp# TCP 模式 — 通过网络端口通信copilot--acp--tcp--port189999.3 应用场景# 在 Zed 编辑器中使用 Copilot # Zed 支持 ACP 协议可以连接 Copilot CLI 作为后端 # 在自定义自动化脚本中使用 Copilot # 通过 ACP 协议发送任务接收结果 # 集成到 CI/CD 流水线 # 使用 ACP Server 模式在构建过程中调用 Copilot10. 最佳实践与注意事项10.1 使用最佳实践提供清晰的上下文在 Chat 中使用workspace、file等引入相关上下文使用自定义指令在项目根目录放置copilot-instructions.md从小任务开始先用小任务测试再逐步加大复杂度审查所有变更即使信任 AI也始终审查生成的代码使用 Agent Mode 时设置合理的审批策略建议终端命令使用ask模式管理 Credits 使用了解哪些操作消耗 Credits优先使用不消耗 Credits 的补全功能10.2 提示工程技巧❌ 差: Fix this ✅ 好: Fix the null pointer exception in line 45 of UserService.java. The issue is that user can be null when fetchById returns empty. ❌ 差: Add tests ✅ 好: Write unit tests for the calculateTotal() function in src/pricing.ts. Cover these edge cases: empty cart, discounted items, and currency conversion errors. ❌ 差: Make it faster ✅ 好: Optimize the database query in getUserOrders() — its currently N1. Use eager loading or a JOIN to reduce queries from O(n) to O(1).10.3 安全注意事项启用 Content Exclusion 排除敏感文件.env、密钥文件等在 Agent Mode 中将终端命令设为ask模式不要将生产环境密钥粘贴到 Chat 中使用企业版时配置安全策略和审计日志10.4 Credits 管理技巧代码补全不消耗 Credits — 充分利用Chat 对话尽量具体减少来回次数Agent Mode 使用复杂任务时消耗较多 — 确保任务描述准确定期检查用量/usageCLI或 GitHub 设置页面Free 用户的 2,000 次补全通常足够日常使用11. 与其他 AI 编程工具的对比11.1 Copilot vs Cursor维度GitHub CopilotCursorIDE 支持6 IDEVS Code, JetBrains, Neovim, Xcode 等仅 Cursor基于 VS Code 的独立编辑器多文件编辑支持Edits / Agent Mode支持内置 Agent价格Free / $10-100/月$20-40/月GitHub 集成原生PR、Issues、Code Review有限模型选择多模型GPT, Claude, Gemini内置模型选择SWE-bench 得分56%51.7%11.2 Copilot vs Windsurf维度GitHub CopilotWindsurfIDE 支持6 IDE仅 Windsurf代理模式支持Agent Mode Cloud Agent支持FlowsCLI支持Copilot CLI有限价格从 Free 开始$20/月起11.3 选择建议需要多 IDE 支持→ Copilot无可争议的最佳选择深度 GitHub 工作流→ Copilot原生集成 PR、Issues、Code Review想要单一编辑器深度优化→ Cursor / Windsurf预算有限→ Copilot Free2000 次补全/月 CLI需要 ACP 协议集成→ Copilot CLI支持 ACP Server 模式附录快速参考A. 常用快捷键操作VS CodeJetBrainsNeovim打开 ChatCtrlShiftIAlt\见配置接受补全TabTabTab查看建议变体CtrlEnter——上一个建议Alt[——下一个建议Alt]——解释选中代码CtrlICtrlI—生成文档—CtrlI—B. 配置文件位置项目路径Copilot CLI 配置~/.config/github-copilot/Copilot CLI 会话~/.config/github-copilot/sessions/VS Code 设置.vscode/settings.json仓库级指令copilot-instructions.md项目根目录内容排除规则.github/copilot-chat.mdC. 官方文档链接GitHub Copilot 主页: https://github.com/features/copilot功能概览: https://docs.github.com/en/copilot/get-started/features快速开始: https://docs.github.com/en/copilot/get-started/quickstart定价方案: https://github.com/features/copilot/plansCopilot CLI 文档: https://docs.github.com/en/copilot/how-tos/copilot-cliACP Server 文档: https://docs.github.com/en/copilot/reference/copilot-cli-reference/acp-serverCloud Agent 文档: https://docs.github.com/copilot/concepts/agents/coding-agent/about-coding-agentVS Code 设置: https://code.visualstudio.com/docs/copilot/setupJetBrains 插件: https://plugins.jetbrains.com/plugin/17718-github-copilot–your-ai-pair-programmer