gh-create-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Pull Request

创建拉取请求

Commit changes, push to remote, and create a pull request with a conventional commit-style title and comprehensive description: $ARGUMENTS
提交更改,推送到远程仓库,并使用约定式提交风格的标题和全面的描述创建拉取请求:$ARGUMENTS

Current Repository State

当前仓库状态

  • Git status: !
    git status --porcelain
  • Current branch: !
    git branch --show-current
  • Default branch: !
    git rev-parse --abbrev-ref origin/HEAD 2>/dev/null | sed 's|origin/||' || echo main
  • Staged changes: !
    git diff --cached --stat
  • Unstaged changes: !
    git diff --stat
  • Recent commits on this branch: !
    git log --oneline -10
  • Existing PR for branch: !
    gh pr view --json number,title,body 2>/dev/null || echo "No existing PR"
  • Git状态:!
    git status --porcelain
  • 当前分支:!
    git branch --show-current
  • 默认分支:!
    git rev-parse --abbrev-ref origin/HEAD 2>/dev/null | sed 's|origin/||' || echo main
  • 已暂存更改:!
    git diff --cached --stat
  • 未暂存更改:!
    git diff --stat
  • 该分支上的近期提交:!
    git log --oneline -10
  • 分支已有PR:!
    gh pr view --json number,title,body 2>/dev/null || echo "No existing PR"

What This Command Does

该命令的功能

  1. Stage and commit changes using conventional commit format (follow the gh-commit skill conventions)
    • If there are unstaged changes, stage and commit them with appropriate conventional commit messages
    • If multiple distinct logical changes exist, create separate commits for each
    • ALWAYS attribute AI-assisted code authorship in commits
  2. Push the branch to the remote repository
    • If the current branch is the default branch (main/master), create a new feature branch first
    • Use
      git push -u origin <branch>
      to set upstream tracking
  3. Analyze all changes in the branch relative to the base branch
    • Run
      git diff origin/<default-branch>...HEAD
      to review the full scope of changes
    • Read relevant modified files to understand the context and impact of changes
  4. Generate a PR title following Conventional Commits format:
    • Format:
      <type>[optional scope]: <description>
    • Types:
      feat
      ,
      fix
      ,
      docs
      ,
      style
      ,
      refactor
      ,
      perf
      ,
      test
      ,
      build
      ,
      ci
      ,
      chore
      ,
      revert
    • Use
      !
      after type/scope for breaking changes:
      feat(api)!: change response format
    • Keep the title concise (under 72 characters)
    • For multi-commit PRs, synthesize a higher-level title that captures the overall theme
  5. Generate a PR description with the structure defined in the PR Description Template below
  6. Create or update the pull request
    • If no PR exists for this branch:
      gh pr create --title "TITLE" --body "DESCRIPTION"
    • If a PR already exists:
      gh pr edit <number> --title "TITLE" --body "DESCRIPTION"
  1. 暂存并提交更改 采用Conventional Commit格式(遵循gh-commit技能约定)
    • 如果存在未暂存更改,暂存这些更改并使用合适的约定式提交信息提交
    • 如果存在多个独立的逻辑变更,为每个变更创建单独的提交
    • 务必在提交中注明AI辅助代码的署名
  2. 推送分支 到远程仓库
    • 如果当前分支是默认分支(main/master),先创建新的功能分支
    • 使用
      git push -u origin <branch>
      设置上游跟踪
  3. 分析分支相对于基准分支的所有变更
    • 运行
      git diff origin/<default-branch>...HEAD
      查看完整的变更范围
    • 读取相关修改文件以了解变更的上下文和影响
  4. 生成符合Conventional Commits格式的PR标题
    • 格式:
      <type>[optional scope]: <description>
    • 类型:
      feat
      ,
      fix
      ,
      docs
      ,
      style
      ,
      refactor
      ,
      perf
      ,
      test
      ,
      build
      ,
      ci
      ,
      chore
      ,
      revert
    • 破坏性变更在类型/范围后添加
      !
      feat(api)!: change response format
    • 保持标题简洁(不超过72个字符)
    • 对于多提交PR,提炼更高层级的标题体现整体变更主题
  5. 按照下方PR描述模板定义的结构生成PR描述
  6. 创建或更新拉取请求
    • 如果该分支不存在PR:
      gh pr create --title "TITLE" --body "DESCRIPTION"
    • 如果该分支已有PR:
      gh pr edit <number> --title "TITLE" --body "DESCRIPTION"

PR Title Examples

PR标题示例

feat(auth): add JWT token refresh endpoint
fix(ui): resolve layout shift on mobile navigation
docs: update API reference for v2 endpoints
refactor(db): migrate from raw SQL to query builder
feat(api)!: change pagination response format
chore(deps): bump TypeScript to 5.x
feat(auth): add JWT token refresh endpoint
fix(ui): resolve layout shift on mobile navigation
docs: update API reference for v2 endpoints
refactor(db): migrate from raw SQL to query builder
feat(api)!: change pagination response format
chore(deps): bump TypeScript to 5.x

PR Description Template

PR描述模板

Use this structure for the PR body. Omit sections that are not applicable.
markdown
undefined
使用该结构编写PR正文,省略不适用的章节。
markdown
undefined

Summary

概述

[1-2 sentence overview of what this PR does and why]
[1-2句话概括该PR的功能和开发背景]

Changes

变更内容

  • [Key change 1]
  • [Key change 2]
  • [Key change 3]
  • [核心变更1]
  • [核心变更2]
  • [核心变更3]

Breaking Changes

破坏性变更

[Describe what breaks and required migration steps]
[描述受影响的功能以及所需的迁移步骤]

Notes

备注

[Additional context, testing instructions, or deployment considerations]
undefined
[额外上下文、测试说明或部署注意事项]
undefined

Guidelines

使用指南

  • Respect existing content: If the PR title already follows conventional commit format, keep it unless it's inaccurate. If a PR already has a meaningful description, enhance it rather than replace it entirely.
  • Issue references: If the branch name contains an issue number (e.g.,
    feat/123-add-auth
    ), reference it in the description with
    Closes #123
    or
    Refs #123
    .
  • Holistic analysis: The PR title should capture the overall intent of the changes, not just list individual commits.
  • Single-commit PRs: The PR title can mirror the commit message.
  • Multi-commit PRs: Synthesize a higher-level title that captures the full scope.
  • Use markdown formatting in the description for readability.
  • 尊重现有内容:如果PR标题已经符合约定式提交格式,除非内容不准确否则保留。如果PR已经有意义完整的描述,优先优化而非完全替换。
  • 关联Issue:如果分支名称包含Issue编号(例如
    feat/123-add-auth
    ),在描述中使用
    Closes #123
    Refs #123
    关联对应Issue。
  • 整体分析:PR标题应体现变更的整体意图,而非仅罗列单个提交内容。
  • 单提交PR:PR标题可与提交信息保持一致。
  • 多提交PR:提炼更高层级的标题覆盖完整变更范围。
  • 在描述中使用markdown格式提升可读性。

Important Notes

重要注意事项

  • By default, pre-commit checks (defined in
    .pre-commit-config.yaml
    ) will run to ensure code quality
    • IMPORTANT: DO NOT SKIP pre-commit checks
  • ALWAYS attribute AI-Assisted Code Authorship in commit messages
  • Always review the diff before generating the title and description to ensure accuracy
  • If
    gh
    CLI is not authenticated, prompt the user to run
    gh auth login
    first
  • 默认会运行pre-commit检查(定义在
    .pre-commit-config.yaml
    中)以保障代码质量
    • 重要提示:请勿跳过pre-commit检查
  • 务必在提交信息中注明AI辅助代码的署名
  • 生成标题和描述前始终检查diff确保内容准确
  • 如果
    gh
    CLI未完成认证,提示用户先运行
    gh auth login