push

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Push

推送

Purpose

用途

  • Push the current branch to
    origin
    safely.
  • Keep branch history clean when the remote has moved forward (coordinate with pull as needed).
  • 安全地将当前分支推送到
    origin
    远程仓库。
  • 当远程仓库分支有更新时,保持本地分支历史记录整洁(必要时与pull技能配合)。

Prerequisites

前提条件

  • Git remote
    origin
    is configured and reachable.
  • Credentials for
    git push
    work for this host (HTTPS or SSH).
  • Git远程仓库
    origin
    已配置且可访问。
  • 用于
    git push
    的凭证在当前主机上可用(HTTPS或SSH方式均可)。

When to Use

使用场景

  • "pushして", "リモートに出して", "origin に push", or similar—when the user asks to push commits to the remote.
  • 当用户提出「pushして」「リモートに出して」「origin に push」或类似需求时——即用户要求将提交推送到远程仓库时使用。

Do Not Use When

禁用场景

  • Only syncing or updating the local branch is needed (use the pull skill).
  • The user wants a PR opened or updated (use the create-pr-jp skill—out of scope for this skill).
  • 仅需要同步或更新本地分支时(请使用pull技能)。
  • 用户需要创建或更新PR时(请使用create-pr-jp技能——此操作不在本技能的范围内)。

Related Skills

相关技能

  • pull: When push is rejected or the branch is not cleanly synced (non-fast-forward, merge conflicts, branch behind remote).
  • create-pr-jp: When the user wants to create or update a GitHub PR (Japanese title/body per repo rules).
  • pull:当推送被拒绝或分支未完全同步时(非快进、合并冲突、分支落后于远程仓库)。
  • create-pr-jp:当用户需要创建或更新GitHub PR时(需遵循仓库规则设置日文标题/正文)。

Procedure

操作步骤

  1. Identify the current branch and inspect remote state (
    git status
    ,
    git remote -v
    ,
    git fetch
    as needed).
  2. Run local checks before pushing:
    pnpm lint
    then
    pnpm test
    (or
    pnpm lint && pnpm test
    ), unless the repo documents different pre-push checks.
  3. Push to
    origin
    , setting upstream tracking if needed (
    git push -u origin HEAD
    ).
  4. If push fails or is non-fast-forward:
    • For non-fast-forward or sync issues: use the pull skill to merge or rebase per repo rules (
      origin/main
      or the appropriate base), resolve conflicts, re-run
      pnpm lint && pnpm test
      , then push again. Use
      --force-with-lease
      only when history was rewritten intentionally.
    • For auth, permissions, or host policy: do not rewrite the remote or change protocols; show the exact error and stop.
  1. 确定当前分支并检查远程仓库状态(必要时执行
    git status
    git remote -v
    git fetch
    命令)。
  2. 推送前先执行本地检查:
    pnpm lint
    然后
    pnpm test
    (或合并为
    pnpm lint && pnpm test
    ),除非仓库文档中指定了其他推送前检查流程。
  3. 将分支推送到
    origin
    ,必要时设置上游跟踪(
    git push -u origin HEAD
    )。
  4. 如果推送失败或出现非快进情况:
    • 针对非快进或同步问题:使用pull技能,按照仓库规则合并或变基(基于
      origin/main
      或相应的基准分支),解决冲突后重新执行
      pnpm lint && pnpm test
      ,然后再次推送。仅当有意重写提交历史时,才可使用
      --force-with-lease
      参数。
    • 针对认证、权限或主机策略问题:请勿重写远程仓库内容或更改协议,直接显示具体错误信息并停止操作。

Output

输出结果

  • A successful
    git push
    to
    origin
    for the current branch (and upstream set when first pushing the branch).
  • 当前分支成功推送到
    origin
    远程仓库(首次推送分支时会设置上游跟踪)。

Usage

使用示例

Reference flow (adapt branch names and commands to the repo):
sh
branch=$(git branch --show-current)
参考流程(可根据仓库情况调整分支名称和命令):
sh
branch=$(git branch --show-current)

Validation gate (lint then test; use repo-specific scripts if documented)

验证环节(先lint再测试;如果仓库有文档说明,请使用仓库特定的脚本)

pnpm lint && pnpm test
pnpm lint && pnpm test

Push (with upstream tracking on first push)

推送(首次推送时设置上游跟踪)

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

If the remote moved: resolve via the pull skill, re-run
pnpm lint && pnpm test
, then:

如果远程仓库有更新:通过pull技能解决问题,重新执行
pnpm lint && pnpm test
,然后执行:

git push -u origin HEAD

git push -u origin HEAD

Auth/permission failures: show the error and stop—do not force-push to fix.

认证/权限失败:显示错误信息并停止——请勿使用强制推送来修复问题。

Only after intentional history rewrite:

仅当有意重写提交历史后:

git push --force-with-lease origin HEAD

git push --force-with-lease origin HEAD

undefined
undefined

Present Results to User

向用户展示结果

  • Confirm the branch name and that the push to
    origin
    succeeded.
  • If push failed, report the exact error and what was tried (e.g. pull/rebase)—do not imply a PR was created or updated (that is create-pr-jp’s job).
  • 确认分支名称,并告知用户已成功推送到
    origin
  • 如果推送失败,报告具体错误信息及已尝试的操作(例如拉取/变基)——请勿暗示已创建或更新PR(该操作属于create-pr-jp技能的范畴)。

Notes

注意事项

  • Never use
    --force
    . Use
    --force-with-lease
    only as a last resort when history was intentionally rewritten.
  • Distinguish sync issues from auth/permission issues: resolve the former with pull; for the latter, surface errors without changing remotes or protocols.
  • 永远不要使用
    --force
    参数。仅当有意重写提交历史时,才可作为最后手段使用
    --force-with-lease
    参数。
  • 区分同步问题与认证/权限问题:前者通过pull技能解决;后者直接显示错误信息,请勿修改远程仓库配置或协议。

Troubleshooting

故障排除

SituationAction
non-fast-forward
/ behind remote
pull skill → merge/rebase per repo rules →
pnpm lint && pnpm test
→ push again
Credential / permission deniedReport verbatim; user fixes credentials or repo access—do not bypass with force push
Wrong remote or branchVerify
git branch --show-current
and
origin
URL before pushing
场景操作
非快进 / 分支落后于远程仓库使用pull技能 → 按照仓库规则合并/变基 → 执行
pnpm lint && pnpm test
→ 再次推送
凭证 / 权限被拒绝直接报告错误信息;由用户修复凭证或仓库访问权限——请勿使用强制推送绕过问题
远程仓库或分支错误推送前先验证
git branch --show-current
origin
的URL