push

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Push

推送代码

Prerequisites

前置条件

  • gh
    CLI is installed and available in
    PATH
    .
  • gh auth status
    succeeds for GitHub operations in this repo.
  • 已安装
    gh
    CLI,且其路径已加入
    PATH
    环境变量。
  • 在当前仓库中执行
    gh auth status
    可成功完成GitHub身份验证。

Goals

目标

  • Push current branch changes to
    origin
    safely.
  • Create a PR if none exists for the branch, otherwise update the existing PR.
  • Keep branch history clean when remote has moved.
  • 安全地将当前分支的变更推送到
    origin
    远程仓库。
  • 若当前分支尚未创建Pull Request(PR)则新建一个,否则更新已存在的PR。
  • 当远程分支有更新时,保持本地分支历史记录的整洁。

Related Skills

相关技能

  • pull
    : use this when push is rejected or sync is not clean (non-fast-forward, merge conflict risk, or stale branch).
  • pull
    :当推送被拒绝或同步不完整时(非快进合并、存在合并冲突风险或分支已过时),请使用该技能。

Steps

步骤

  1. Identify current branch and confirm remote state.
  2. Run local validation (
    make -C elixir all
    ) before pushing.
  3. Push branch to
    origin
    with upstream tracking if needed, using whatever remote URL is already configured.
  4. If push is not clean/rejected:
    • If the failure is a non-fast-forward or sync problem, run the
      pull
      skill to merge
      origin/main
      , resolve conflicts, and rerun validation.
    • Push again; use
      --force-with-lease
      only when history was rewritten.
    • If the failure is due to auth, permissions, or workflow restrictions on the configured remote, stop and surface the exact error instead of rewriting remotes or switching protocols as a workaround.
  5. Ensure a PR exists for the branch:
    • If no PR exists, create one.
    • If a PR exists and is open, update it.
    • If branch is tied to a closed/merged PR, create a new branch + PR.
    • Write a proper PR title that clearly describes the change outcome
    • For branch updates, explicitly reconsider whether current PR title still matches the latest scope; update it if it no longer does.
  6. Write/update PR body explicitly using
    .github/pull_request_template.md
    :
    • Fill every section with concrete content for this change.
    • Replace all placeholder comments (
      <!-- ... -->
      ).
    • Keep bullets/checkboxes where template expects them.
    • If PR already exists, refresh body content so it reflects the total PR scope (all intended work on the branch), not just the newest commits, including newly added work, removed work, or changed approach.
    • Do not reuse stale description text from earlier iterations.
  7. Validate PR body with
    mix pr_body.check
    and fix all reported issues.
  8. Reply with the PR URL from
    gh pr view
    .
  1. 识别当前分支并确认远程仓库状态。
  2. 推送前执行本地验证(
    make -C elixir all
    )。
  3. 若需要,将分支推送到
    origin
    并设置上游跟踪,使用已配置的远程仓库URL。
  4. 若推送失败/被拒绝:
    • 若失败原因是非快进合并或同步问题,执行
      pull
      技能合并
      origin/main
      分支,解决冲突后重新执行验证。
    • 再次尝试推送;仅当本地分支历史被重写时,才使用
      --force-with-lease
      参数。
    • 若失败原因是身份验证、权限或远程仓库的工作流限制问题,请停止操作并明确提示具体错误,不要通过修改远程仓库配置或切换协议来规避问题。
  5. 确保当前分支已关联PR:
    • 若不存在PR,则新建一个。
    • 若存在已打开的PR,则更新该PR。
    • 若当前分支关联的PR已被关闭/合并,则创建新分支并新建PR。
    • 编写清晰描述变更成果的PR标题。
    • 当分支更新时,需重新确认当前PR标题是否仍符合最新的变更范围;若范围已变更则更新标题。
  6. 参照
    .github/pull_request_template.md
    编写/更新PR正文:
    • 为本次变更填充模板中的所有章节内容。
    • 替换所有占位符注释(
      <!-- ... -->
      )。
    • 保留模板要求的项目符号/复选框格式。
    • 若PR已存在,请刷新正文内容使其反映分支上的全部预期工作(而非仅最新提交),包括新增、移除的工作或变更的实现方案。
    • 不要重复使用早期版本的陈旧描述文本。
  7. 使用
    mix pr_body.check
    验证PR正文,并修复所有检测到的问题。
  8. 回复时附上
    gh pr view
    命令返回的PR URL。

Commands

命令

sh
undefined
sh
undefined

Identify branch

识别当前分支

branch=$(git branch --show-current)
branch=$(git branch --show-current)

Minimal validation gate

基础验证环节

make -C elixir all
make -C elixir all

Initial push: respect the current origin remote.

首次推送:遵循当前配置的origin远程仓库.

git push -u origin HEAD
git push -u origin HEAD

If that failed because the remote moved, use the pull skill. After

若因远程分支更新导致推送失败,请使用pull技能。在通过pull技能解决问题并重新验证后,重试常规推送:

pull-skill resolution and re-validation, retry the normal push:

git push -u origin HEAD
git push -u origin HEAD

If the configured remote rejects the push for auth, permissions, or workflow

若已配置的远程仓库因身份验证、权限或工作流限制拒绝推送,请停止操作并明确提示具体错误。

restrictions, stop and surface the exact error.

仅当本地分支历史被重写时使用:

Only if history was rewritten locally:

git push --force-with-lease origin HEAD
git push --force-with-lease origin HEAD

Ensure a PR exists (create only if missing)

确保PR已存在(仅在不存在时新建)

pr_state=$(gh pr view --json state -q .state 2>/dev/null || true) if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then echo "Current branch is tied to a closed PR; create a new branch + PR." >&2 exit 1 fi
pr_state=$(gh pr view --json state -q .state 2>/dev/null || true) if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then echo "Current branch is tied to a closed PR; create a new branch + PR." >&2 exit 1 fi

Write a clear, human-friendly title that summarizes the shipped change.

编写清晰、易懂的PR标题,概括本次变更的内容。

pr_title="<clear PR title written for this change>" if [ -z "$pr_state" ]; then gh pr create --title "$pr_title" else

Reconsider title on every branch update; edit if scope shifted.

gh pr edit --title "$pr_title" fi
pr_title="<clear PR title written for this change>" if [ -z "$pr_state" ]; then gh pr create --title "$pr_title" else

每次分支更新时重新审视标题;若变更范围已调整则编辑标题。

gh pr edit --title "$pr_title" fi

Write/edit PR body to match .github/pull_request_template.md before validation.

在验证前,参照.github/pull_request_template.md编写/编辑PR正文。

Example workflow:

示例流程:

1) open the template and draft body content for this PR

1) open the template and draft body content for this PR

2) gh pr edit --body-file /tmp/pr_body.md

2) gh pr edit --body-file /tmp/pr_body.md

3) for branch updates, re-check that title/body still match current diff

3) for branch updates, re-check that title/body still match current diff

tmp_pr_body=$(mktemp) gh pr view --json body -q .body > "$tmp_pr_body" (cd elixir && mix pr_body.check --file "$tmp_pr_body") rm -f "$tmp_pr_body"
tmp_pr_body=$(mktemp) gh pr view --json body -q .body > "$tmp_pr_body" (cd elixir && mix pr_body.check --file "$tmp_pr_body") rm -f "$tmp_pr_body"

Show PR URL for the reply

回复时展示PR URL

gh pr view --json url -q .url
undefined
gh pr view --json url -q .url
undefined

Notes

注意事项

  • Do not use
    --force
    ; only use
    --force-with-lease
    as the last resort.
  • Distinguish sync problems from remote auth/permission problems:
    • Use the
      pull
      skill for non-fast-forward or stale-branch issues.
    • Surface auth, permissions, or workflow restrictions directly instead of changing remotes or protocols.
  • 请勿使用
    --force
    参数;仅在万不得已时使用
    --force-with-lease
  • 区分同步问题与远程仓库的身份验证/权限问题:
    • 对于非快进合并或分支过时问题,使用
      pull
      技能。
    • 若为身份验证、权限或工作流限制问题,请直接提示具体错误,不要修改远程仓库配置或切换协议。