github-copilot-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Copilot CLI Skill

GitHub Copilot CLI 技能

Skill by ara.so — Devtools Skills collection.
GitHub Copilot CLI brings AI-powered development assistance directly to your terminal. It enables code review, debugging, test generation, code explanation, and custom AI agents without leaving the command line. Think of it as having an expert developer available 24/7 in your terminal who can read your codebase, explain patterns, generate code, and help troubleshoot issues.
ara.so 提供的技能 — 开发工具技能合集。
GitHub Copilot CLI 将AI驱动的开发辅助功能直接带到你的终端中。它支持在不离开命令行的情况下进行代码审查、调试、测试生成、代码解释以及自定义AI Agent操作。你可以把它看作是一位24/7在线的资深开发者,能读取你的代码库、解释代码模式、生成代码并帮助排查问题。

Installation

安装

Prerequisites

前置要求

  • GitHub account with Copilot access (free tier, subscription, or education)
  • GitHub CLI (
    gh
    ) version 2.62.0 or later
  • Terminal access
  • 拥有Copilot访问权限的GitHub账户(免费版、订阅版或教育版)
  • 版本2.62.0或更高的GitHub CLI(
    gh
  • 终端访问权限

Install GitHub CLI

安装GitHub CLI

macOS:
bash
brew install gh
Windows:
bash
winget install --id GitHub.cli
Linux (Debian/Ubuntu):
bash
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
macOS:
bash
brew install gh
Windows:
bash
winget install --id GitHub.cli
Linux(Debian/Ubuntu):
bash
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh

Install Copilot CLI Extension

安装Copilot CLI扩展

bash
gh extension install github/gh-copilot
bash
gh extension install github/gh-copilot

Authenticate

身份验证

bash
gh auth login
Follow the prompts to authenticate with your GitHub account that has Copilot access.
bash
gh auth login
按照提示使用拥有Copilot访问权限的GitHub账户完成身份验证。

Verify Installation

验证安装

bash
gh copilot --version
bash
gh copilot --version

Core Commands

核心命令

Interactive Chat Mode

交互式聊天模式

Start an interactive conversation with Copilot:
bash
gh copilot
This opens a conversational interface where you can ask questions, get code suggestions, and iterate on solutions.
启动与Copilot的交互式对话:
bash
gh copilot
这会打开一个对话界面,你可以在其中提问、获取代码建议并迭代解决方案。

Quick Explain

快速解释

Get quick explanations without entering interactive mode:
bash
gh copilot explain "git rebase -i HEAD~3"
bash
gh copilot explain "docker-compose up -d"
无需进入交互模式即可获取快速解释:
bash
gh copilot explain "git rebase -i HEAD~3"
bash
gh copilot explain "docker-compose up -d"

Quick Suggest

快速建议

Get command suggestions for tasks:
bash
gh copilot suggest "find all python files modified in last 7 days"
bash
gh copilot suggest "compress all jpg files in current directory"
获取针对特定任务的命令建议:
bash
gh copilot suggest "find all python files modified in last 7 days"
bash
gh copilot suggest "compress all jpg files in current directory"

Aliases (Shortcuts)

别名(快捷方式)

Set up convenient aliases:
bash
gh copilot alias -- --shell bash
This creates three aliases:
  • ghcs
    - suggest commands
  • ghce
    - explain commands
  • ghcp
    - open Copilot chat
After setup, you can use:
bash
ghcs "list all running docker containers"
ghce "kubectl get pods -A"
设置便捷的别名:
bash
gh copilot alias -- --shell bash
这会创建三个别名:
  • ghcs
    - 命令建议
  • ghce
    - 命令解释
  • ghcp
    - 打开Copilot聊天
设置完成后,你可以使用:
bash
ghcs "list all running docker containers"
ghce "kubectl get pods -A"

Interaction Modes

交互模式

1. Chat Mode (Interactive)

1. 聊天模式(交互式)

Best for: Complex problems, iterative development, multi-step workflows
bash
gh copilot
Example conversation:
> I need to review a Python Flask application for security issues

Copilot: I'll help you review your Flask application for security. Could you share:
1. The main application file
2. Any authentication/authorization code
3. Database interaction code

> @app.py @auth.py @models.py

Copilot: [Analyzes files and provides security review]
最适合:复杂问题、迭代开发、多步骤工作流
bash
gh copilot
对话示例:
> 我需要审查一个Python Flask应用的安全问题

Copilot:我会帮你审查Flask应用的安全性。能否分享以下内容:
1. 主应用文件
2. 任何身份验证/授权代码
3. 数据库交互代码

> @app.py @auth.py @models.py

Copilot:[分析文件并提供安全审查结果]

2. Explain Mode

2. 解释模式

Best for: Understanding unfamiliar commands, code snippets, or error messages
bash
gh copilot explain "awk '{print $2}' file.txt | sort -u"
bash
gh copilot explain "SELECT u.name, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id"
最适合:理解陌生命令、代码片段或错误信息
bash
gh copilot explain "awk '{print $2}' file.txt | sort -u"
bash
gh copilot explain "SELECT u.name, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id"

3. Suggest Mode

3. 建议模式

Best for: Getting shell commands for specific tasks
bash
gh copilot suggest "recursively delete all node_modules folders"
bash
gh copilot suggest "monitor CPU and memory usage in real-time"
最适合:获取针对特定任务的Shell命令
bash
gh copilot suggest "recursively delete all node_modules folders"
bash
gh copilot suggest "monitor CPU and memory usage in real-time"

Context Awareness

上下文感知

File Context (@-mentions)

文件上下文(@提及)

Reference specific files in your prompts:
bash
gh copilot
> Review @server.py for potential race conditions
bash
gh copilot
> Compare @config.dev.json and @config.prod.json and explain differences
在提示中引用特定文件:
bash
gh copilot
> 审查@server.py中潜在的竞态条件
bash
gh copilot
> 对比@config.dev.json和@config.prod.json并解释差异

Multi-File Context

多文件上下文

Reference multiple files for comprehensive analysis:
bash
gh copilot
> @models.py @views.py @serializers.py review this Django app for N+1 queries
引用多个文件进行全面分析:
bash
gh copilot
> @models.py @views.py @serializers.py 审查这个Django应用的N+1查询问题

Directory Context

目录上下文

Analyze entire directories:
bash
gh copilot
> @src/ explain the architecture of this application
分析整个目录:
bash
gh copilot
> @src/ 解释这个应用的架构

Development Workflows

开发工作流

Code Review

代码审查

bash
gh copilot
> Review @pull_request_changes.diff for:
> - Security vulnerabilities
> - Performance issues
> - Code style violations
> - Missing error handling
bash
gh copilot
> 审查@pull_request_changes.diff中的以下内容:
> - 安全漏洞
> - 性能问题
> - 代码风格违规
> - 缺失的错误处理

Debugging

调试

bash
gh copilot
> I'm getting "TypeError: Cannot read property 'map' of undefined" in @app.js line 42
> Here's the error stack: @error.log
bash
gh copilot
> 我的@app.js第42行出现了"TypeError: Cannot read property 'map' of undefined"错误
> 这是错误堆栈:@error.log

Test Generation

测试生成

For Python:
bash
gh copilot
> Generate pytest unit tests for @calculator.py covering edge cases
For JavaScript:
bash
gh copilot
> Create Jest tests for @api-client.js including error scenarios
For Go:
bash
gh copilot
> Write table-driven tests for @handler.go
针对Python:
bash
gh copilot
> 为@calculator.py生成覆盖边缘情况的pytest单元测试
针对JavaScript:
bash
gh copilot
> 为@api-client.js创建包含错误场景的Jest测试
针对Go:
bash
gh copilot
> 为@handler.go编写表驱动测试

Refactoring

重构

bash
gh copilot
> Refactor @legacy-auth.js to use async/await instead of callbacks
bash
gh copilot
> Convert @class-component.jsx to a functional component with hooks
bash
gh copilot
> 将@legacy-auth.js重构为使用async/await替代回调函数
bash
gh copilot
> 将@class-component.jsx转换为带hooks的函数式组件

Custom Agents and Instructions

自定义Agent与指令

Creating Custom Agents

创建自定义Agent

Agents are reusable AI assistants with specific expertise. Create an agent configuration:
bash
mkdir -p ~/.config/gh-copilot/agents
Security Review Agent (
~/.config/gh-copilot/agents/security-reviewer.md
):
markdown
undefined
Agent是具有特定专业能力的可复用AI助手。创建Agent配置:
bash
mkdir -p ~/.config/gh-copilot/agents
安全审查Agent
~/.config/gh-copilot/agents/security-reviewer.md
):
markdown
undefined

Security Reviewer Agent

安全审查Agent

You are a security-focused code reviewer specializing in:
  • OWASP Top 10 vulnerabilities
  • Input validation and sanitization
  • Authentication and authorization flaws
  • SQL injection and XSS prevention
  • Secrets and credential management
Always:
  1. Identify specific line numbers with issues
  2. Explain the security impact
  3. Provide secure code examples
  4. Reference relevant OWASP guidelines

**Python Expert Agent** (`~/.config/gh-copilot/agents/python-expert.md`):

```markdown
你是专注于安全的代码审查专家,擅长:
  • OWASP Top 10漏洞
  • 输入验证与清理
  • 身份验证与授权缺陷
  • SQL注入与XSS防护
  • 密钥与凭证管理
始终遵循:
  1. 指出存在问题的具体行号
  2. 解释安全影响
  3. 提供安全代码示例
  4. 引用相关OWASP指南

**Python专家Agent**(`~/.config/gh-copilot/agents/python-expert.md`):

```markdown

Python Expert Agent

Python专家Agent

You are a Python expert focusing on:
  • PEP 8 style compliance
  • Type hints and mypy compatibility
  • Pythonic idioms and patterns
  • Performance optimization
  • Testing with pytest
Provide:
  • Specific improvement suggestions
  • Code examples following best practices
  • Performance benchmarks when relevant
undefined
你是Python专家,专注于:
  • PEP 8风格合规
  • 类型提示与mypy兼容性
  • Pythonic惯用法与模式
  • 性能优化
  • 使用pytest进行测试
提供:
  • 具体的改进建议
  • 遵循最佳实践的代码示例
  • 相关的性能基准测试
undefined

Using Agents

使用Agent

bash
gh copilot
> @security-reviewer analyze @app.py
bash
gh copilot
> @python-expert review @data_processor.py for optimization opportunities
bash
gh copilot
> @security-reviewer 分析@app.py
bash
gh copilot
> @python-expert 审查@data_processor.py的优化空间

Custom Instructions (Global)

全局自定义指令

Set global instructions that apply to all interactions:
bash
mkdir -p ~/.config/gh-copilot
Create
~/.config/gh-copilot/instructions.md
:
markdown
undefined
设置适用于所有交互的全局指令:
bash
mkdir -p ~/.config/gh-copilot
创建
~/.config/gh-copilot/instructions.md
markdown
undefined

My Development Preferences

我的开发偏好

  • Language: Prefer TypeScript over JavaScript
  • Testing: Use Jest with React Testing Library
  • Style: Follow Airbnb style guide
  • Error Handling: Always use try-catch and log errors
  • Comments: Add JSDoc comments for public functions
  • Security: Flag any hardcoded credentials or secrets
undefined
  • 语言:优先使用TypeScript而非JavaScript
  • 测试:使用Jest搭配React Testing Library
  • 风格:遵循Airbnb风格指南
  • 错误处理:始终使用try-catch并记录错误
  • 注释:为公共函数添加JSDoc注释
  • 安全:标记任何硬编码的凭证或密钥
undefined

Skills (Automated Context)

技能(自动化上下文)

Skills are automatically loaded based on your project structure.
技能会根据你的项目结构自动加载。

Creating a Skill

创建技能

Create
.copilot/skills/
directory in your project:
bash
mkdir -p .copilot/skills
Django Project Skill (
.copilot/skills/django-project.md
):
markdown
undefined
在你的项目中创建
.copilot/skills/
目录:
bash
mkdir -p .copilot/skills
Django项目技能
.copilot/skills/django-project.md
):
markdown
undefined

Django Project Configuration

Django项目配置

Stack

技术栈

  • Django 4.2
  • PostgreSQL 15
  • Redis for caching
  • Celery for async tasks
  • Django 4.2
  • PostgreSQL 15
  • Redis用于缓存
  • Celery用于异步任务

Code Standards

代码标准

  • Use Django REST Framework serializers
  • Prefer class-based views
  • Always use select_related/prefetch_related
  • Write tests with pytest-django
  • 使用Django REST Framework序列化器
  • 优先使用基于类的视图
  • 始终使用select_related/prefetch_related
  • 使用pytest-django编写测试

Database

数据库

  • Use migrations for all schema changes
  • Never use raw SQL without parameterization
  • Connection: via DATABASE_URL environment variable

**React Project Skill** (`.copilot/skills/react-conventions.md`):

```markdown
  • 所有架构变更都使用迁移
  • 绝不使用未参数化的原生SQL
  • 连接:通过DATABASE_URL环境变量

**React项目技能**(`.copilot/skills/react-conventions.md`):

```markdown

React Project Conventions

React项目约定

Stack

技术栈

  • React 18 with TypeScript
  • Vite for bundling
  • React Query for data fetching
  • Zustand for state management
  • React 18搭配TypeScript
  • Vite用于打包
  • React Query用于数据获取
  • Zustand用于状态管理

Patterns

模式

  • Functional components with hooks
  • Custom hooks for reusable logic
  • Error boundaries for fault tolerance
  • Suspense for loading states
  • 带hooks的函数式组件
  • 用于可复用逻辑的自定义hooks
  • 用于容错的错误边界
  • 用于加载状态的Suspense

File Structure

文件结构

  • Components in src/components
  • Hooks in src/hooks
  • Utils in src/utils

Skills are automatically loaded when you run `gh copilot` in a directory containing `.copilot/skills/`.
  • 组件位于src/components
  • Hooks位于src/hooks
  • 工具函数位于src/utils

当你在包含`.copilot/skills/`的目录中运行`gh copilot`时,技能会自动加载。

MCP Server Integration

MCP服务器集成

Model Context Protocol (MCP) servers extend Copilot CLI with external data sources and APIs.
Model Context Protocol(MCP)服务器可通过外部数据源和API扩展Copilot CLI的功能。

Configuration File

配置文件

Create
~/.config/gh-copilot/mcp.json
:
json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "${DATABASE_URL}"
      }
    }
  }
}
创建
~/.config/gh-copilot/mcp.json
json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "${DATABASE_URL}"
      }
    }
  }
}

Available MCP Servers

可用的MCP服务器

GitHub Integration:
json
{
  "github": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-github"],
    "env": {
      "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
    }
  }
}
Usage:
bash
gh copilot
> Search GitHub for recent issues tagged "bug" in owner/repo
PostgreSQL Database:
json
{
  "postgres": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-postgres"],
    "env": {
      "DATABASE_URL": "${DATABASE_URL}"
    }
  }
}
Usage:
bash
gh copilot
> Query the database for users created in the last 30 days
Filesystem Access:
json
{
  "filesystem": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
  }
}
Brave Search:
json
{
  "brave-search": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-brave-search"],
    "env": {
      "BRAVE_API_KEY": "${BRAVE_API_KEY}"
    }
  }
}
GitHub集成:
json
{
  "github": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-github"],
    "env": {
      "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
    }
  }
}
用法:
bash
gh copilot
> 在owner/repo仓库中搜索最近标记为"bug"的问题
PostgreSQL数据库:
json
{
  "postgres": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-postgres"],
    "env": {
      "DATABASE_URL": "${DATABASE_URL}"
    }
  }
}
用法:
bash
gh copilot
> 查询数据库中过去30天创建的用户
文件系统访问:
json
{
  "filesystem": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
  }
}
Brave搜索:
json
{
  "brave-search": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-brave-search"],
    "env": {
      "BRAVE_API_KEY": "${BRAVE_API_KEY}"
    }
  }
}

Creating Custom MCP Servers

创建自定义MCP服务器

MCP servers are command-line tools that implement the MCP protocol. Example structure:
javascript
// my-mcp-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({
  name: 'my-custom-server',
  version: '1.0.0',
});

// Define tools
server.setRequestHandler('tools/list', async () => ({
  tools: [{
    name: 'get_data',
    description: 'Fetch data from custom source',
    inputSchema: {
      type: 'object',
      properties: {
        query: { type: 'string' }
      }
    }
  }]
}));

// Implement tool
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;
  
  if (name === 'get_data') {
    const result = await fetchCustomData(args.query);
    return { content: [{ type: 'text', text: JSON.stringify(result) }] };
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);
Add to
mcp.json
:
json
{
  "my-custom": {
    "command": "node",
    "args": ["/path/to/my-mcp-server.js"]
  }
}
MCP服务器是实现MCP协议的命令行工具。示例结构:
javascript
// my-mcp-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({
  name: 'my-custom-server',
  version: '1.0.0',
});

// 定义工具
server.setRequestHandler('tools/list', async () => ({
  tools: [{
    name: 'get_data',
    description: 'Fetch data from custom source',
    inputSchema: {
      type: 'object',
      properties: {
        query: { type: 'string' }
      }
    }
  }]
}));

// 实现工具
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;
  
  if (name === 'get_data') {
    const result = await fetchCustomData(args.query);
    return { content: [{ type: 'text', text: JSON.stringify(result) }] };
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);
添加到
mcp.json
json
{
  "my-custom": {
    "command": "node",
    "args": ["/path/to/my-mcp-server.js"]
  }
}

Real-World Examples

实际场景示例

Example 1: Code Review Workflow

示例1:代码审查工作流

bash
undefined
bash
undefined

Start review session

启动审查会话

gh copilot
I need to review changes before committing. Review @src/auth.py @src/models.py for:
  1. Security issues
  2. Performance problems
  3. Code style
  4. Missing tests
gh copilot
我需要在提交前审查变更。审查@src/auth.py @src/models.py的以下内容:
  1. 安全问题
  2. 性能问题
  3. 代码风格
  4. 缺失的测试

Copilot provides detailed review

Copilot提供详细审查结果

Generate pytest tests for the issues you found in @src/auth.py
为@src/auth.py中你发现的问题生成pytest测试

Copilot generates test code

Copilot生成测试代码

Now explain how to fix the SQL injection vulnerability you identified
undefined
现在解释如何修复你发现的SQL注入漏洞
undefined

Example 2: Debugging Session

示例2:调试会话

bash
gh copilot

> My Flask app is returning 500 errors. Here's the traceback: @error.log
> And here's the relevant code: @app.py @database.py
bash
gh copilot

> 我的Flask应用返回500错误。这是回溯信息:@error.log
> 这是相关代码:@app.py @database.py

Copilot analyzes and suggests fixes

Copilot分析并建议修复方案

Apply your suggested fix to @database.py and show me the corrected code
Now write a test that would have caught this bug
undefined
将你建议的修复应用到@database.py并展示修正后的代码
现在编写一个能提前发现这个bug的测试
undefined

Example 3: Test Generation

示例3:测试生成

bash
gh copilot

> Generate comprehensive Jest tests for @api-client.ts covering:
> - Successful API calls
> - Network errors
> - Invalid responses
> - Timeout scenarios
> - Retry logic
bash
gh copilot

> 为@api-client.ts生成全面的Jest测试,覆盖:
> - 成功的API调用
> - 网络错误
> - 无效响应
> - 超时场景
> - 重试逻辑

Copilot generates test suite

Copilot生成测试套件

Add tests for the edge case where the API returns 429 rate limit
undefined
添加针对API返回429限流的边缘情况测试
undefined

Example 4: Multi-File Refactoring

示例4:多文件重构

bash
gh copilot

> I need to refactor @legacy-app/ to use modern React patterns:
> - Convert class components to functional components with hooks
> - Replace Redux with Zustand
> - Add TypeScript types
> Start with @legacy-app/components/UserList.jsx
bash
gh copilot

> 我需要将@legacy-app/重构为使用现代React模式:
> - 将类组件转换为带hooks的函数式组件
> - 用Zustand替代Redux
> - 添加TypeScript类型
> 从@legacy-app/components/UserList.jsx开始

Copilot provides refactored code

Copilot提供重构后的代码

Continue with @legacy-app/components/UserDetail.jsx using the same patterns
undefined
继续按照相同模式重构@legacy-app/components/UserDetail.jsx
undefined

Example 5: Database Query Optimization

示例5:数据库查询优化

bash
gh copilot

> @models.py contains Django ORM queries. Analyze for N+1 query problems
bash
gh copilot

> @models.py包含Django ORM查询。分析其中的N+1查询问题

Copilot identifies issues

Copilot识别问题

Show me how to fix the N+1 issue in the get_user_orders view using select_related
Now generate a test that verifies the query count is optimized
undefined
展示如何使用select_related修复get_user_orders视图中的N+1问题
现在生成一个验证查询计数已优化的测试
undefined

Configuration Files

配置文件

Main Config Directory

主配置目录

~/.config/gh-copilot/
├── instructions.md          # Global instructions
├── mcp.json                # MCP server configuration
└── agents/                 # Custom agent definitions
    ├── security-reviewer.md
    ├── python-expert.md
    └── react-specialist.md
~/.config/gh-copilot/
├── instructions.md          # 全局指令
├── mcp.json                # MCP服务器配置
└── agents/                 # 自定义Agent定义
    ├── security-reviewer.md
    ├── python-expert.md
    └── react-specialist.md

Project-Level Skills

项目级技能

your-project/
├── .copilot/
│   └── skills/
│       ├── project-conventions.md
│       ├── api-documentation.md
│       └── deployment-guide.md
├── src/
└── tests/
your-project/
├── .copilot/
│   └── skills/
│       ├── project-conventions.md
│       ├── api-documentation.md
│       └── deployment-guide.md
├── src/
└── tests/

Common Patterns

常见模式

Pattern 1: Multi-Step Feature Development

模式1:多步骤功能开发

bash
gh copilot

> I need to add user authentication to my Flask app
bash
gh copilot

> 我需要为我的Flask应用添加用户身份验证

Copilot outlines approach

Copilot概述实现方案

Start by showing me the User model with password hashing
Now create the login endpoint with JWT tokens
Generate tests for the authentication flow
Show me how to protect routes with auth middleware
undefined
先展示带密码哈希的User模型
现在创建带JWT令牌的登录端点
为身份验证流程生成测试
展示如何用认证中间件保护路由
undefined

Pattern 2: Legacy Code Understanding

模式2:遗留代码理解

bash
gh copilot

> @legacy-system/ is an old codebase I inherited. Help me understand:
> 1. The overall architecture
> 2. How data flows through the system
> 3. External dependencies
> 4. Potential technical debt
bash
gh copilot

> @legacy-system/是我接手的旧代码库。帮我理解:
> 1. 整体架构
> 2. 系统中的数据流
> 3. 外部依赖
> 4. 潜在的技术债务

Analyze incrementally

逐步分析

Start with @legacy-system/main.py and @legacy-system/config.py
undefined
先从@legacy-system/main.py和@legacy-system/config.py开始
undefined

Pattern 3: Security Audit

模式3:安全审计

bash
gh copilot

> @security-reviewer perform a complete security audit of @api/
bash
gh copilot

> @security-reviewer 对@api/进行完整的安全审计

Review findings

查看审计结果

Prioritize the vulnerabilities by severity
For each critical issue, show me the fix with code examples
Generate security tests that verify the fixes
undefined
按严重程度对漏洞进行优先级排序
针对每个关键问题,展示带代码示例的修复方案
生成验证修复效果的安全测试
undefined

Pattern 4: Documentation Generation

模式4:文档生成

bash
gh copilot

> Generate API documentation for @endpoints.py in OpenAPI format

> Create a README.md for @utils/ explaining each utility function

> Add inline comments to @complex-algorithm.py explaining the logic
bash
gh copilot

> 为@endpoints.py生成OpenAPI格式的API文档

> 为@utils/创建README.md,解释每个工具函数

> 为@complex-algorithm.py添加解释逻辑的内联注释

Pattern 5: Migration Planning

模式5:迁移规划

bash
gh copilot

> I need to migrate from @old-api/ (REST) to @new-api/ (GraphQL)
> Create a migration plan with backwards compatibility

> Show me how to implement the first endpoint in both versions

> Generate tests that verify both APIs return identical data
bash
gh copilot

> 我需要从@old-api/(REST)迁移到@new-api/(GraphQL)
> 创建一个兼容旧版本的迁移计划

> 展示如何在两个版本中实现第一个端点

> 生成验证两个API返回相同数据的测试

Troubleshooting

故障排除

Installation Issues

安装问题

Problem:
gh: command not found
bash
undefined
问题:
gh: command not found
bash
undefined

Verify installation

验证安装

which gh
which gh

Reinstall GitHub CLI

重新安装GitHub CLI

brew reinstall gh # macOS

**Problem: Extension install fails**
```bash
brew reinstall gh # macOS

**问题:扩展安装失败**
```bash

List installed extensions

列出已安装的扩展

gh extension list
gh extension list

Remove and reinstall

卸载并重新安装

gh extension remove gh-copilot gh extension install github/gh-copilot
undefined
gh extension remove gh-copilot gh extension install github/gh-copilot
undefined

Authentication Issues

身份验证问题

Problem: "Not authenticated" error
bash
undefined
问题:"Not authenticated"错误
bash
undefined

Check auth status

检查身份验证状态

gh auth status
gh auth status

Re-authenticate

重新验证

gh auth login
gh auth login

Verify Copilot access

验证Copilot访问权限

gh copilot --version

**Problem: "No Copilot subscription"**
- Verify your GitHub account has Copilot access at https://github.com/settings/copilot
- Check if you're using the correct account: `gh auth status`
gh copilot --version

**问题:"No Copilot subscription"**
- 在https://github.com/settings/copilot验证你的GitHub账户是否拥有Copilot访问权限
- 检查是否使用了正确的账户:`gh auth status`

Context Issues

上下文问题

Problem: Copilot can't find referenced files
bash
undefined
问题:Copilot无法找到引用的文件
bash
undefined

Use absolute paths

使用绝对路径

gh copilot
Review /full/path/to/file.py
gh copilot
审查/full/path/to/file.py

Or navigate to project directory first

或者先导航到项目目录

cd /path/to/project gh copilot
Review @src/file.py

**Problem: Too much context, slow responses**
```bash
cd /path/to/project gh copilot
审查@src/file.py

**问题:上下文过多,响应缓慢**
```bash

Be specific with file references

明确文件引用

Review @src/auth.py # Good Review @src/ # Too broad
undefined
审查@src/auth.py # 推荐 审查@src/ # 范围过广
undefined

Agent/Skill Issues

Agent/技能问题

Problem: Custom agent not loading
bash
undefined
问题:自定义Agent未加载
bash
undefined

Verify file location

验证文件位置

ls ~/.config/gh-copilot/agents/
ls ~/.config/gh-copilot/agents/

Check file format (must be .md)

检查文件格式(必须为.md)

Verify no syntax errors in frontmatter

验证前置内容无语法错误


**Problem: Skill not activating**
```bash

**问题:技能未激活**
```bash

Verify skill directory

验证技能目录

ls .copilot/skills/
ls .copilot/skills/

Must run gh copilot from project directory

必须从项目目录运行gh copilot

pwd # Should be in project root
pwd # 应位于项目根目录

Restart copilot session

重启Copilot会话

gh copilot
undefined
gh copilot
undefined

MCP Server Issues

MCP服务器问题

Problem: MCP server not connecting
bash
undefined
问题:MCP服务器无法连接
bash
undefined

Verify mcp.json syntax

验证mcp.json语法

cat ~/.config/gh-copilot/mcp.json | jq .
cat ~/.config/gh-copilot/mcp.json | jq .

Check environment variables

检查环境变量

echo $GITHUB_TOKEN echo $DATABASE_URL
echo $GITHUB_TOKEN echo $DATABASE_URL

Test server manually

手动测试服务器

npx -y @modelcontextprotocol/server-github

**Problem: Server timeouts**
- Check network connectivity
- Verify API credentials are valid
- Check server logs if available
npx -y @modelcontextprotocol/server-github

**问题:服务器超时**
- 检查网络连接
- 验证API凭证有效
- 查看服务器日志(如果可用)

Performance Issues

性能问题

Problem: Slow responses
  • Reduce context size (fewer @-mentions)
  • Use more specific queries
  • Check internet connection
  • Try during off-peak hours
Problem: High token usage
  • Be concise in prompts
  • Avoid pasting large files
  • Use @-mentions instead of pasting code
  • Break complex tasks into smaller steps
问题:响应缓慢
  • 减少上下文大小(减少@提及的文件数量)
  • 使用更具体的查询
  • 检查网络连接
  • 尝试在非高峰时段使用
问题:令牌使用量过高
  • 提示要简洁
  • 避免粘贴大文件
  • 使用@提及替代粘贴代码
  • 将复杂任务拆分为多个小步骤

Best Practices

最佳实践

  1. Be Specific: "Review @auth.py for SQL injection" is better than "Review my code"
  2. Use Context Wisely: Reference only files relevant to your question
  3. Iterate: Start with a focused question, then drill down based on responses
  4. Create Agents: Build specialized agents for recurring tasks (security reviews, code style checks)
  5. Document with Skills: Keep project conventions in
    .copilot/skills/
    for consistent assistance
  6. Leverage MCP: Connect to databases, APIs, and tools your project actually uses
  7. Review Suggestions: Always review generated code before applying it
  8. Combine Modes: Use
    suggest
    for quick commands,
    chat
    for complex problems
  9. Save Useful Patterns: Document working prompts in your project's
    .copilot/skills/
  10. Environment Variables: Never hardcode secrets; always use env vars in MCP configs
  1. 明确具体:“审查@auth.py中的SQL注入问题”比“审查我的代码”效果更好
  2. 合理使用上下文:仅引用与问题相关的文件
  3. 迭代提问:从聚焦的问题开始,根据响应逐步深入
  4. 创建Agent:为重复任务(安全审查、代码风格检查)构建专用Agent
  5. 用技能记录文档:在
    .copilot/skills/
    中保存项目约定,以获得一致的辅助
  6. 利用MCP:连接到项目实际使用的数据库、API和工具
  7. 审查建议内容:应用生成的代码前务必进行审查
  8. 组合使用模式
    suggest
    用于快速命令,
    chat
    用于复杂问题
  9. 保存有用模式:在项目的
    .copilot/skills/
    中记录有效的提示
  10. 环境变量:绝不硬编码密钥;在MCP配置中始终使用环境变量

Additional Resources

额外资源