git-pr-create
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR Create
创建PR
Create GitHub pull requests via .
gh pr create通过创建GitHub拉取请求。
gh pr createFormat
格式
Title: Commit subject or change summary
Body:
undefined标题: 提交主题或变更摘要
正文:
undefinedSummary
摘要
- Change description (bullets OK)
- 变更描述(可使用项目符号)
Test plan
测试计划
- Verification steps
undefined- 验证步骤
undefinedWorkflow
工作流程
- Verify not on main/master
- Check for existing PR on branch
- Detect base branch
- Generate title from commits
- Build body with summary + test plan
- Create PR
- 确认当前不在main/master分支
- 检查当前分支是否已有PR
- 检测基准分支
- 根据提交记录生成标题
- 构建包含摘要和测试计划的正文
- 创建PR
Commands
命令
bash
undefinedbash
undefinedCheck 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 )"
undefinedTitle Generation
标题生成
Use first commit subject from branch, or summarize if multiple commits:
bash
undefined使用分支中的第一条提交主题,若存在多个提交则汇总变更:
bash
undefinedSingle 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
undefinedgit log origin/main..HEAD --oneline
undefinedBody 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 when:
--draft- 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 :
--basebash
gh pr create --base develop --title "$TITLE" --body "$BODY"自动检测基准分支:
bash
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'使用参数手动指定:
--basebash
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