create-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

How to Create a Pull Request Using GitHub CLI

如何使用GitHub CLI创建拉取请求

This guide explains how to create pull requests using GitHub CLI in our project.
Important: All PR titles and descriptions should be written in English.
本指南说明如何在我们的项目中使用GitHub CLI创建拉取请求。
重要提示:所有PR标题和描述都必须使用英文撰写。

Prerequisites

前提条件

Check if
gh
is installed, if not follow this instruction to install it:
  1. Install GitHub CLI if you haven't already:
    bash
    # macOS
    brew install gh
    
    # Windows
    winget install --id GitHub.cli
    
    # Linux
    # Follow instructions at https://github.com/cli/cli/blob/trunk/docs/install_linux.md
  2. Authenticate with GitHub:
    bash
    gh auth login
检查是否已安装
gh
,如果未安装,请按照以下说明进行安装:
  1. 安装GitHub CLI(如果尚未安装):
    bash
    # macOS
    brew install gh
    
    # Windows
    winget install --id GitHub.cli
    
    # Linux
    # 按照https://github.com/cli/cli/blob/trunk/docs/install_linux.md上的说明操作
  2. 与GitHub进行身份验证:
    bash
    gh auth login

Pre-flight Checks

预检查

Before creating a PR, check for uncommitted changes:
  1. Run
    git status
    to check for uncommitted changes (staged, unstaged, or untracked files)
  2. If uncommitted changes exist, use the Skill tool to run the
    commit
    skill first:
    Skill: commit
  3. This ensures all your work is committed before creating the PR
在创建PR之前,检查是否有未提交的更改:
  1. 运行
    git status
    检查未提交的更改(已暂存、未暂存或未跟踪的文件)
  2. 如果存在未提交的更改,请先使用Skill工具运行
    commit
    技能:
    Skill: commit
  3. 这确保你在创建PR之前已提交所有工作内容

Creating a New Pull Request

创建新的拉取请求

  1. First, prepare your PR description following the template in @.github/pull_request_template.md
  2. Use the
    gh pr create --draft
    command to create a new pull request:
    bash
    # Basic command structure
    gh pr create --draft --title "✨(scope): Your descriptive title" --body "Your PR description" --base main 
    For more complex PR descriptions with proper formatting, use the
    --body-file
    option with the exact PR template structure:
    bash
    # Create PR with proper template structure
    gh pr create --draft --title "✨(scope): Your descriptive title" --body-file .github/pull_request_template.md --base main
  1. 首先,按照@.github/pull_request_template.md中的模板准备你的PR描述
  2. 使用
    gh pr create --draft
    命令创建新的拉取请求:
    bash
    # 基础命令结构
    gh pr create --draft --title "✨(scope): Your descriptive title" --body "Your PR description" --base main 
    对于格式规范的更复杂PR描述,请结合
    --body-file
    选项使用完整的PR模板结构:
    bash
    # 使用规范模板结构创建PR
    gh pr create --draft --title "✨(scope): Your descriptive title" --body-file .github/pull_request_template.md --base main

Best Practices

最佳实践

  1. Language: Always use English for PR titles and descriptions
  2. PR Title Format: Use conventional commit format with emojis
    • Always include an appropriate emoji at the beginning of the title
    • Use the actual emoji character (not the code representation like
      :sparkles:
      )
    • Examples:
      • ✨(supabase): Add staging remote configuration
      • 🐛(auth): Fix login redirect issue
      • 📝(readme): Update installation instructions
  3. Description Template: Always use our PR template structure from @.github/pull_request_template.md:
  4. Template Accuracy: Ensure your PR description precisely follows the template structure:
    • Don't modify or rename the PR-Agent sections (
      pr_agent:summary
      and
      pr_agent:walkthrough
      )
    • Keep all section headers exactly as they appear in the template
    • Don't add custom sections that aren't in the template
  5. Draft PRs: Start as draft when the work is in progress
    • Use
      --draft
      flag in the command
    • Convert to ready for review when complete using
      gh pr ready
  1. 语言:PR标题和描述始终使用英文
  2. PR标题格式:使用带有表情符号的约定式提交格式
    • 标题开头必须包含合适的表情符号
    • 使用实际的表情符号字符(而非
      :sparkles:
      这类代码表示)
    • 示例:
      • ✨(supabase): Add staging remote configuration
      • 🐛(auth): Fix login redirect issue
      • 📝(readme): Update installation instructions
  3. 描述模板:始终使用我们从@.github/pull_request_template.md获取的PR模板结构:
  4. 模板准确性:确保你的PR描述严格遵循模板结构:
    • 不要修改或重命名PR-Agent部分(
      pr_agent:summary
      pr_agent:walkthrough
    • 保持所有章节标题与模板中的完全一致
    • 不要添加模板中未定义的自定义章节
  5. 草稿PR:当工作仍在进行中时,以草稿形式创建
    • 在命令中使用
      --draft
      标志
    • 完成后使用
      gh pr ready
      将其转换为待审核状态

Common Mistakes to Avoid

需避免的常见错误

  1. Using Non-English Text: All PR content must be in English
  2. Incorrect Section Headers: Always use the exact section headers from the template
  3. Adding Custom Sections: Stick to the sections defined in the template
  4. Using Outdated Templates: Always refer to the current @.github/pull_request_template.md file
  1. 使用非英文文本:所有PR内容必须使用英文
  2. 章节标题错误:始终使用模板中的准确章节标题
  3. 添加自定义章节:严格遵循模板中定义的章节
  4. 使用过时模板:始终参考当前的@.github/pull_request_template.md文件

Missing Sections

缺失章节

Always include all template sections, even if some are marked as "N/A" or "None"
始终包含模板的所有章节,即使某些章节标记为"N/A"或"None"

Additional GitHub CLI PR Commands

其他GitHub CLI PR命令

Here are some additional useful GitHub CLI commands for managing PRs:
bash
undefined
以下是一些用于管理PR的实用GitHub CLI命令:
bash
undefined

List your open pull requests

列出你所有的开放拉取请求

gh pr list --author "@me"
gh pr list --author "@me"

Check PR status

检查PR状态

gh pr status
gh pr status

View a specific PR

查看特定PR

gh pr view <PR-NUMBER>
gh pr view <PR-NUMBER>

Check out a PR branch locally

在本地检出PR分支

gh pr checkout <PR-NUMBER>
gh pr checkout <PR-NUMBER>

Convert a draft PR to ready for review

将草稿PR转换为待审核状态

gh pr ready <PR-NUMBER>
gh pr ready <PR-NUMBER>

Add reviewers to a PR

为PR添加审核人

gh pr edit <PR-NUMBER> --add-reviewer username1,username2
gh pr edit <PR-NUMBER> --add-reviewer username1,username2

Merge a PR

合并PR

gh pr merge <PR-NUMBER> --squash
undefined
gh pr merge <PR-NUMBER> --squash
undefined

Using Templates for PR Creation

使用模板创建PR

To simplify PR creation with consistent descriptions, you can create a template file:
  1. Create a file named
    pr-template.md
    with your PR template
  2. Use it when creating PRs:
bash
gh pr create --draft --title "feat(scope): Your title" --body-file pr-template.md --base main
为简化PR创建并保持描述一致性,你可以创建一个模板文件:
  1. 创建名为
    pr-template.md
    的文件,写入你的PR模板
  2. 创建PR时使用该文件:
bash
gh pr create --draft --title "feat(scope): Your title" --body-file pr-template.md --base main

Related Documentation

相关文档