git-push

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Push Skill

Git Push Skill

<scripts>
<scripts>

Available scripts

可用脚本

ScriptPurpose
scripts/git-push.sh [--force]
Discover repos, check for unpushed commits, and push safely
</scripts> <objective>
  • Push unpushed commits to the remote for all discovered repositories.
  • Do nothing if there are no commits to push.
  • Block unsafe operations (force push to main/master, detached HEAD).
</objective>
<trigger_conditions>
User intentActivate
"push"yes
"git push"yes
"/git-push"yes
"push my changes"yes
"push commits to remote"yes
"sync to remote"yes
requests that only ask for commit/rebase/resetno
"push back on this idea" (non-git context)no
</trigger_conditions>
<argument_validation>
If ARGUMENT is missing:
  • Push all unpushed commits in all discovered repositories.
If ARGUMENT is
--force
:
  • Use
    --force-with-lease
    for push. Protected branches (main/master) are still blocked.
</argument_validation>
<scope_assumptions>
  • Start from the current working directory. If it is not a git repository, inspect descendant directories for git repositories.
  • Push only. Do not commit, amend, rebase, or rewrite history.
  • No confirmation needed — if there are commits to push, push them immediately.
  • Use Bash commands only.
</scope_assumptions>
<required>
CategoryRule
SafetyNever force push to main or master.
SafetyNever push from detached HEAD.
SafetyUse
--force-with-lease
instead of
--force
when force pushing.
UpstreamIf no upstream is set, push with
-u origin <branch>
to set tracking.
IdempotentIf already up to date, report and exit cleanly.
Multi-repoHandle descendant repositories independently.
</required> <forbidden>
CategoryAvoid
Force push
--force
to main or master
History rewriteamend, rebase, reset, or other history-editing commands
CommitDo not create commits — that is the git-commit skill's job
Raw force
git push --force
— always use
--force-with-lease
</forbidden> <workflow>
Script用途
scripts/git-push.sh [--force]
识别仓库,检查未推送的提交并安全推送
</scripts> <objective>
  • 将所有识别到的仓库中的未推送提交推送到远程仓库。
  • 如果没有需要推送的提交则不执行任何操作。
  • 阻止不安全操作(强制推送到main/master分支、分离HEAD状态)。
</objective>
<trigger_conditions>
用户意图是否触发
"push"
"git push"
"/git-push"
"push my changes"
"push commits to remote"
"sync to remote"
仅请求提交/变基/重置的需求
"push back on this idea"(非Git场景)
</trigger_conditions>
<argument_validation>
如果缺少参数:
  • 推送所有识别到的仓库中所有未推送的提交。
如果参数为
--force
  • 使用
    --force-with-lease
    进行推送。受保护分支(main/master)仍会被阻止。
</argument_validation>
<scope_assumptions>
  • 从当前工作目录开始。如果当前目录不是Git仓库,则检查子目录中的Git仓库。
  • 仅执行推送操作。不执行提交、修改提交、变基或重写历史的操作。
  • 无需确认——如果有需要推送的提交,立即推送。
  • 仅使用Bash命令。
</scope_assumptions>
<required>
类别规则
安全性绝不强制推送到main或master分支。
安全性绝不从分离HEAD状态推送。
安全性强制推送时使用
--force-with-lease
而非
--force
上游设置如果未设置上游分支,使用
-u origin <branch>
推送以建立跟踪关系。
幂等性如果已经与上游同步,报告状态并正常退出。
多仓库处理独立处理子目录中的仓库。
</required> <forbidden>
类别禁止操作
强制推送对main或master分支使用
--force
历史重写修改提交、变基、重置或其他编辑历史的命令
提交操作不创建提交——这是git-commit技能的职责
直接强制推送使用
git push --force
——始终使用
--force-with-lease
</forbidden> <workflow>

Run the script

运行脚本

bash
scripts/git-push.sh
Or with force:
bash
scripts/git-push.sh --force
The script handles everything:
  1. Discovers repositories (current directory or descendants).
  2. For each repository, checks the branch and upstream status.
  3. Skips repositories with no unpushed commits, detached HEAD, or protected branch conflicts.
  4. Pushes repositories that have commits ahead of upstream.
  5. Reports a summary of pushed, skipped, and failed repositories.
</workflow> <examples>
bash
scripts/git-push.sh
或带强制参数:
bash
scripts/git-push.sh --force
脚本会处理所有操作:
  1. 识别仓库(当前目录或子目录)。
  2. 对每个仓库,检查分支和上游状态。
  3. 跳过没有未推送提交、处于分离HEAD状态或存在受保护分支冲突的仓库。
  4. 推送那些提交领先于上游的仓库。
  5. 报告已推送、已跳过和推送失败的仓库汇总信息。
</workflow> <examples>

Simple push

简单推送

text
/git-push
Result: discovers repos, pushes any that have unpushed commits.
text
/git-push
结果:识别仓库,推送所有存在未推送提交的仓库。

Force push (feature branch)

强制推送(功能分支)

text
/git-push --force
Result: pushes with
--force-with-lease
. Blocked on main/master.
text
/git-push --force
结果:使用
--force-with-lease
推送。在main/master分支上会被阻止。

Nothing to push

无内容可推送

text
/git-push
Result: reports "Already up to date" and exits cleanly.
text
/git-push
结果:报告“Already up to date”并正常退出。

Multi-repo push

多仓库推送

text
/git-push
Result: discovers descendant repos, pushes each independently, reports summary.
</examples> <validation>
  • Confirm the script was executed, not manual git commands.
  • Confirm force push was not used on main/master.
  • Confirm detached HEAD was skipped.
  • Confirm the summary output was reported to the user.
</validation>
text
/git-push
结果:识别子目录中的仓库,独立推送每个仓库,报告汇总信息。
</examples> <validation>
  • 确认执行的是脚本而非手动Git命令。
  • 确认未对main/master分支使用强制推送。
  • 确认已跳过分离HEAD状态的仓库。
  • 确认已向用户报告汇总输出信息。
</validation>