create-pull-request
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Pull Request
创建Pull Request
This skill guides you through creating a well-structured GitHub pull request that follows project conventions and best practices.
本技能将引导你创建符合项目规范和最佳实践的结构清晰的GitHub Pull Request。
Prerequisites Check
前置条件检查
Before proceeding, verify the following:
在开始之前,请验证以下内容:
1. Check if gh
CLI is installed
gh1. 检查是否已安装gh
CLI
ghbash
gh --versionIf not installed, inform the user:
The GitHub CLI () is required but not installed. Please install it:gh
- macOS:
brew install gh- Other: https://cli.github.com/
bash
gh --version如果未安装,请告知用户:
GitHub CLI()为必需工具但未安装。请进行安装:gh
- macOS:
brew install gh- 其他系统:https://cli.github.com/
2. Check if authenticated with GitHub
2. 检查是否已通过GitHub认证
bash
gh auth statusIf not authenticated, guide the user to run .
gh auth loginbash
gh auth status如果未认证,请引导用户运行。
gh auth login3. Verify clean working directory
3. 验证工作目录是否干净
bash
git statusIf there are uncommitted changes, ask the user whether to:
- Commit them as part of this PR
- Stash them temporarily
- Discard them (with caution)
bash
git status如果存在未提交的变更,请询问用户选择以下操作:
- 将它们作为本次PR的一部分提交
- 暂时储藏它们
- 丢弃它们(请谨慎操作)
Gather Context
收集上下文信息
1. Identify the current branch
1. 识别当前分支
bash
git branch --show-currentEnsure you're not on or . If so, ask the user to create or switch to a feature branch.
mainmasterbash
git branch --show-current确保你不在或分支上。如果是,请询问用户创建或切换到功能分支。
mainmaster2. Find the base branch
2. 找到基础分支
bash
git remote show origin | grep "HEAD branch"This is typically or .
mainmasterbash
git remote show origin | grep "HEAD branch"基础分支通常是或。
mainmaster3. Analyze recent commits relevant to this PR
3. 分析与本次PR相关的近期提交
bash
git log origin/main..HEAD --oneline --no-decorateReview these commits to understand:
- What changes are being introduced
- The scope of the PR (single feature/fix or multiple changes)
- Whether commits should be squashed or reorganized
bash
git log origin/main..HEAD --oneline --no-decorate查看这些提交以了解:
- 引入了哪些变更
- PR的范围(单个功能/修复或多个变更)
- 是否需要压缩或重新整理提交
4. Review the diff
4. 查看差异
bash
git diff origin/main..HEAD --statThis shows which files changed and helps identify the type of change.
bash
git diff origin/main..HEAD --stat这会显示哪些文件被修改,有助于识别变更类型。
Information Gathering
信息收集
Before creating the PR, you need the following information. Check if it can be inferred from:
- Commit messages
- Branch name (e.g., ,
fix/issue-123)feature/new-login - Changed files and their content
If any critical information is missing, use to ask the user:
ask_followup_question在创建PR之前,你需要以下信息。检查是否可以从以下来源推断:
- 提交消息
- 分支名称(例如、
fix/issue-123)feature/new-login - 修改的文件及其内容
如果缺少关键信息,请使用询问用户:
ask_followup_questionRequired Information
必填信息
- Related Issue Number: Look for patterns like ,
#123, orfixes #123in commit messagescloses #123 - Description: What problem does this solve? Why were these changes made?
- Type of Change: Bug fix, new feature, breaking change, refactor, cosmetic, documentation, or workflow
- Test Procedure: How was this tested? What could break?
- 相关Issue编号:在提交消息中查找类似、
#123或fixes #123的格式closes #123 - 描述:本次变更解决了什么问题?为什么进行这些变更?
- 变更类型:Bug修复、新功能、破坏性变更、重构、外观调整、文档更新或工作流变更
- 测试流程:如何测试本次变更?可能会有哪些部分受影响?
Example clarifying question
示例澄清问题
If the issue number is not found:
I couldn't find a related issue number in the commit messages or branch name. What GitHub issue does this PR address? (Enter the issue number, e.g., "123" or "N/A" for small fixes)
如果未找到Issue编号:
我在提交消息或分支名称中未找到相关Issue编号。本次PR对应的GitHub Issue是什么?(请输入Issue编号,例如"123",小修复可输入"N/A")
Git Best Practices
Git最佳实践
Before creating the PR, consider these best practices:
在创建PR之前,请考虑以下最佳实践:
Commit Hygiene
提交规范
- Atomic commits: Each commit should represent a single logical change
- Clear commit messages: Follow conventional commit format when possible
- No merge commits: Prefer rebasing over merging to keep history clean
- 原子提交:每个提交应代表一个独立的逻辑变更
- 清晰的提交消息:尽可能遵循约定式提交格式
- 无合并提交:优先使用变基而非合并以保持历史记录整洁
Branch Management
分支管理
-
Rebase on latest main (if needed):bash
git fetch origin git rebase origin/main -
Squash if appropriate: If there are many small "WIP" commits, consider interactive rebase:bash
git rebase -i origin/mainOnly suggest this if commits appear messy and the user is comfortable with rebasing.
-
基于最新main分支变基(如有需要):bash
git fetch origin git rebase origin/main -
适当压缩提交:如果存在许多小型的"WIP"(进行中)提交,考虑使用交互式变基:bash
git rebase -i origin/main仅当提交记录混乱且用户熟悉变基操作时才建议此操作。
Push Changes
推送变更
Ensure all commits are pushed:
bash
git push origin HEADIf the branch was rebased, you may need:
bash
git push origin HEAD --force-with-lease确保所有提交已推送:
bash
git push origin HEAD如果分支已变基,可能需要执行:
bash
git push origin HEAD --force-with-leaseCreate the Pull Request
创建Pull Request
IMPORTANT: Read and use the PR template at . The PR body format must strictly match the template structure. Do not deviate from the template format.
.github/pull_request_template.mdWhen filling out the template:
- Replace with the actual issue number, or keep as
#XXXXif no issue exists (for small fixes)#XXXX - Fill in all sections with relevant information gathered from commits and context
- Mark the appropriate "Type of Change" checkbox(es)
- Complete the "Pre-flight Checklist" items that apply
重要提示:请阅读并使用中的PR模板。PR正文格式必须严格匹配模板结构,请勿偏离模板格式。
.github/pull_request_template.md填写模板时:
- 将替换为实际Issue编号,若无Issue则保留
#XXXX(适用于小型修复)#XXXX - 使用从提交和上下文收集到的相关信息填写所有章节
- 勾选对应的“变更类型”复选框
- 完成适用的“飞行前检查”项
Create PR with gh CLI
通过gh CLI创建PR
bash
gh pr create --title "PR_TITLE" --body "PR_BODY" --base mainAlternatively, create as draft if the user wants review before marking ready:
bash
gh pr create --title "PR_TITLE" --body "PR_BODY" --base main --draftbash
gh pr create --title "PR_TITLE" --body "PR_BODY" --base main或者,如果用户希望先获得审核再标记为就绪,可创建草稿PR:
bash
gh pr create --title "PR_TITLE" --body "PR_BODY" --base main --draftPost-Creation
创建后操作
After creating the PR:
- Display the PR URL so the user can review it
- Remind about CI checks: Tests and linting will run automatically
- Suggest next steps:
- Add reviewers if needed:
gh pr edit --add-reviewer USERNAME - Add labels if needed:
gh pr edit --add-label "bug"
- Add reviewers if needed:
创建PR后:
- 显示PR链接以便用户查看
- 提醒CI检查:测试和代码检查将自动运行
- 建议后续步骤:
- 如需添加审核者:
gh pr edit --add-reviewer USERNAME - 如需添加标签:
gh pr edit --add-label "bug"
- 如需添加审核者:
Error Handling
错误处理
Common Issues
常见问题
-
No commits ahead of main: The branch has no changes to submit
- Ask if the user meant to work on a different branch
-
Branch not pushed: Remote doesn't have the branch
- Push the branch first:
git push -u origin HEAD
- Push the branch first:
-
PR already exists: A PR for this branch already exists
- Show the existing PR:
gh pr view - Ask if they want to update it instead
- Show the existing PR:
-
Merge conflicts: Branch conflicts with base
- Guide user through resolving conflicts or rebasing
-
没有领先于main分支的提交:当前分支没有可提交的变更
- 询问用户是否打算在其他分支上工作
-
分支未推送:远程仓库中不存在该分支
- 先推送分支:
git push -u origin HEAD
- 先推送分支:
-
PR已存在:该分支对应的PR已存在
- 显示现有PR:
gh pr view - 询问用户是否要更新现有PR
- 显示现有PR:
-
合并冲突:分支与基础分支存在冲突
- 引导用户解决冲突或重新变基
Summary Checklist
总结检查清单
Before finalizing, ensure:
- CLI is installed and authenticated
gh - Working directory is clean
- All commits are pushed
- Branch is up-to-date with base branch
- Related issue number is identified, or placeholder is used
- PR description follows the template exactly
- Appropriate type of change is selected
- Pre-flight checklist items are addressed
最终确认前,请确保:
- CLI已安装并完成认证
gh - 工作目录干净
- 所有提交已推送
- 分支已与基础分支保持同步
- 已识别相关Issue编号,或已使用占位符
- PR描述完全遵循模板格式
- 已选择合适的变更类型
- 已处理飞行前检查项