用途:管理 fork 仓库、与上游同步、干净地回馈贡献。适用判断标准包括:理解 fork 远程架构、诊断 fork 与上游分叉、同步 fork 主分支、决定同步策略、无法直连上游时进行贡献等;若已准备好向上游提 PR,则资料建议改用 git-upstream-pr。
主要能力:识别 origin(自己的 fork)与 upstream(原仓库)两个远程;先运行数据收集脚本检测分叉状态,脚本为纯函数、不产生变更:bash "${CLAUDE_SKILL_DIR}/scripts/git-fork-workflow.sh" --home-dir "$HOME" --project-dir "$(pwd)"。解析输出中的 STATUS= 与 ISSUES:,得到 IS_FORK、UPSTREAM/ORIGIN、BEHIND/AHEAD、RECOMMENDED_STRATEGY(in-sync、fast-forward、ahead-only、rebase、not-a-fork)。分叉计数由 git rev-list --left-right --count upstream/main...origin/main 得出。
同步策略:资料给出四种。GitHub CLI 同步 gh repo sync owner/fork-repo 后 git pull origin main;快进合并 git fetch upstream 与 git merge --ff-only upstream/main;硬重置 git fetch upstream、git reset --hard upstream/main、git push --force-with-lease origin main;变基 git fetch upstream、git rebase upstream/main、git push --force-with-lease origin main。脚本推荐仅是建议,执行 reset、rebase、force-push 等破坏性操作由使用者决定。
向上游提 PR 的黄金法则:从 upstream/main 而非 fork 的 main 拉分支,可绕开分叉问题:git fetch upstream、git switch -c feat/my-contribution upstream/main、git push -u origin feat/my-contribution。跨 fork PR 需用 --head your-username:feat/branch-name 并指定 --repo owner/upstream-repo。
限制与其它:squash 合并会使 SHA 与上游不同从而产生分叉;无法直连上游时可先在 fork main 暂存,但不要把 fork:main 直接 PR 到 upstream:main,而应之后在可达上游的环境从 upstream/main 新拉分支 cherry-pick 提交。具体脚本参数与行为细节部分暂未提供完整说明。