git-pr-create

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PR Create

创建PR

Create GitHub pull requests via
gh pr create
.
通过
gh pr create
创建GitHub拉取请求。

Format

格式

Title: Commit subject or change summary
Body:
undefined
标题: 提交主题或变更摘要
正文:
undefined

Summary

摘要

  • Change description (bullets OK)
  • 变更描述(可使用项目符号)

Test plan

测试计划

  • Verification steps
undefined
  • 验证步骤
undefined

Workflow

工作流程

  1. Verify not on main/master
  2. Check for existing PR on branch
  3. Detect base branch
  4. Generate title from commits
  5. Build body with summary + test plan
  6. Create PR
  1. 确认当前不在main/master分支
  2. 检查当前分支是否已有PR
  3. 检测基准分支
  4. 根据提交记录生成标题
  5. 构建包含摘要和测试计划的正文
  6. 创建PR

Commands

命令

bash
undefined
bash
undefined

Check current branch

查看当前分支

git branch --show-current
git branch --show-current

Check for existing PR

检查是否已有PR

gh pr list --head $(git branch --show-current)
gh pr list --head $(git branch --show-current)

Create PR

创建PR

gh pr create --title "$TITLE" --body "$(cat <<'EOF'
gh pr create --title "$TITLE" --body "$(cat <<'EOF'

Summary

摘要

  • Change 1
  • Change 2
  • 变更1
  • 变更2

Test plan

测试计划

  • Test item EOF )"
undefined
  • 测试项 EOF )"
undefined

Title Generation

标题生成

Use first commit subject from branch, or summarize if multiple commits:
bash
undefined
使用分支中的第一条提交主题,若存在多个提交则汇总变更:
bash
undefined

Single commit - use subject

单个提交 - 使用提交主题

git log origin/main..HEAD --format='%s' | head -1
git log origin/main..HEAD --format='%s' | head -1

Multiple commits - summarize changes

多个提交 - 汇总变更

git log origin/main..HEAD --oneline
undefined
git log origin/main..HEAD --oneline
undefined

Body Style

正文格式

Bullets allowed in PR body (unlike commit messages):
  • Summary section lists changes
  • Test plan uses checkboxes
Keep concise. One line per logical change.
PR正文中允许使用项目符号(与提交消息不同):
  • 摘要部分列出变更内容
  • 测试计划使用复选框
保持简洁,每个逻辑变更占一行。

Draft PRs

草稿PR

Use
--draft
when:
  • Work in progress
  • User requests draft
  • Waiting for CI setup
bash
gh pr create --draft --title "$TITLE" --body "$BODY"
在以下场景使用
--draft
参数:
  • 工作进行中
  • 用户要求创建草稿
  • 等待CI配置完成
bash
gh pr create --draft --title "$TITLE" --body "$BODY"

Base Branch

基准分支

Detect automatically:
bash
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
Override with
--base
:
bash
gh pr create --base develop --title "$TITLE" --body "$BODY"
自动检测基准分支:
bash
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
使用
--base
参数手动指定:
bash
gh pr create --base develop --title "$TITLE" --body "$BODY"

Safety

安全机制

  • Verify branch is not main/master before creating
  • Check for existing PR to avoid duplicates
  • Never create PR from main to main
  • 创建前确认当前分支不是main/master
  • 检查是否已有PR以避免重复创建
  • 禁止从main分支向main分支创建PR