GitHub Copilot CLI 速查表
GitHub Copilot CLI 是 GitHub 推出的 AI 终端助手,通过 gh 扩展提供命令建议(suggest)和命令解释(explain)功能,帮助你在终端中更高效地工作。
概述
GitHub Copilot CLI 将 AI 辅助能力引入终端,让你用自然语言描述需求,即可获得命令建议或解释。作为 gh 扩展安装,与 GitHub 生态深度集成。
快速开始
``bash
# 安装 GitHub CLI(如未安装)
# macOS
brew install gh
# Ubuntu/Debian
sudo apt install gh
# 安装 Copilot CLI 扩展 gh extension install github/gh-copilot
# 登录 GitHub gh auth login --web
# 使用 Suggest 功能 gh copilot suggest "Find all large log files" ``
详细用法请参阅下方命令表格。
安装与设置
Copilot CLI 作为 gh 扩展分发,安装前需确保已安装 GitHub CLI (>= 2.0.0) 并登录 GitHub 账号。支持 macOS、Linux 和 Windows。
命令建议 (Suggest)
使用自然语言描述想要完成的操作,Copilot CLI 会推荐对应的终端命令。支持交互式选择和直接执行。快捷别名 ghcs 提供更快的访问。
命令解释 (Explain)
粘贴或输入终端命令,Copilot CLI 会用自然语言解释命令的作用、参数含义和执行效果,帮助理解复杂命令或学习新工具。
配置与别名
通过 gh copilot config 管理设置,使用 gh copilot alias 为 bash、zsh 或 PowerShell 设置快捷别名。支持 GH_HOST 环境变量和 --hostname 参数指定 GitHub Enterprise 实例。
安装配置(6)
| 命令 | 难度 | ||
|---|---|---|---|
gh extension install安装 Copilot CLI gh 扩展 | 基础 | gh extension install github/gh-copilot | |
gh auth login --web通过浏览器登录 GitHub 账号 | 基础 | gh auth login --web | |
gh auth login通过 Token 登录 GitHub 账号 | 基础 | gh auth login --with-token < token.txt | |
gh copilot --help查看 Copilot CLI 帮助信息 | 基础 | gh copilot --help | |
gh extension upgrade升级 Copilot CLI 扩展到最新版本 | 基础 | gh extension upgrade gh-copilot | |
gh extension remove卸载 Copilot CLI 扩展 | 基础 | gh extension remove gh-copilot |
命令建议(6)
| 命令 | 难度 | ||
|---|---|---|---|
gh copilot suggest根据自然语言描述建议终端命令 | 基础 | gh copilot suggest 'Find all files larger than 100MB' | |
gh copilot suggest -t指定命令类型(shell/gh/git) | 中级 | gh copilot suggest -t gh 'List all open issues' | |
gh copilot suggest -t shell获取通用 Shell 命令建议 | 基础 | gh copilot suggest -t shell 'Monitor disk space' | |
gh copilot suggest -t git获取 Git 命令建议 | 基础 | gh copilot suggest -t git 'Undo last commit keeping changes' | |
gh copilot suggest -t gh获取 GitHub CLI 命令建议 | 基础 | gh copilot suggest -t gh 'Create a new release' | |
Execute suggested command选择执行 suggest 推荐的命令 | 中级 | gh copilot suggest 'Remove temp files' -> Select 'Execute' |
命令解释(3)
| 命令 | 难度 | ||
|---|---|---|---|
gh copilot explain解释终端命令的作用和参数 | 基础 | gh copilot explain 'git rebase -i HEAD~3' | |
gh copilot explain complex解释复杂管道命令的每个部分 | 高级 | gh copilot explain 'ps aux | grep python | awk "{print \$2}" | xargs kill -9' | |
gh copilot explain --full完整解释命令的每个选项和参数 | 中级 | gh copilot explain --full 'docker run -d --name web -p 80:80 nginx' |
配置偏好(6)
| 命令 | 难度 | ||
|---|---|---|---|
gh copilot config查看或修改 Copilot CLI 配置 | 中级 | gh copilot config | |
gh copilot config set设置配置项的值 | 中级 | gh copilot config set editor vim | |
gh copilot config get查看指定配置项的值 | 中级 | gh copilot config get editor | |
--hostname指定 GitHub Enterprise Server 主机名 | 中级 | gh copilot suggest --hostname github.mycompany.com 'List repos' | |
GH_HOST环境变量设置 GitHub Enterprise 主机名 | 中级 | export GH_HOST=github.mycompany.com | |
gh copilot version查看 Copilot CLI 版本 | 基础 | gh copilot version |
别名定制(6)
| 命令 | 难度 | ||
|---|---|---|---|
gh copilot alias设置 Shell 别名(交互式向导) | 基础 | gh copilot alias | |
gh copilot alias bash为 Bash 设置别名(ghcs/ghce) | 基础 | gh copilot alias bash >> ~/.bashrc | |
gh copilot alias zsh为 Zsh 设置别名(ghcs/ghce) | 基础 | gh copilot alias zsh >> ~/.zshrc | |
gh copilot alias pwsh为 PowerShell 设置别名(ghcs/ghce) | 基础 | gh copilot alias pwsh >> $PROFILE | |
ghcsgh copilot suggest 的快捷别名 | 基础 | ghcs 'Kill process on port 3000' | |
ghcegh copilot explain 的快捷别名 | 基础 | ghce 'lsof -i :3000' |