← ClaudeAtlas

gh-mergelisted

将当前分支合并到 GitHub 目标分支(通常是 main)。 自动处理代码提交、创建 PR、监控 CI Checks、处理错误直到合并成功。
AgentsMesh/AgentsMesh · ★ 2,147 · Code & Development · score 86
Install: claude install-skill AgentsMesh/AgentsMesh
# GitHub 合并代码流程 将当前分支的代码通过 Pull Request 合并到 GitHub 目标分支。 ## 使用方式 ``` /gh-merge # 合并到 main(默认) /gh-merge develop # 合并到 develop 分支 /gh-merge --squash # 使用 squash 方式合并 ``` ## 使用流程 ### 1. 确认状态 ```bash git status git branch --show-current git remote -v gh auth status ``` **前置检查:** - 当前分支不能是目标分支 - `gh` CLI 已认证 - **识别 GitHub remote 名称**:检查 `git remote -v` 输出,找到指向 `github.com` 的 remote(可能是 `origin`、`github` 或其他名称),后续所有 git push/fetch 命令都使用该 remote 名称 ### 2. 提交代码 如有未提交的更改,先提交: ```bash git add <files> git commit -m "feat/fix/refactor: 描述更改内容" git push -u <github-remote> <current-branch> ``` **注意:** - 优先 `git add <具体文件>` 而非 `git add .`,避免意外提交敏感文件 - push 时使用步骤 1 识别的 GitHub remote 名称 ### 3. Rebase 到最新目标分支 合并前先 rebase,减少冲突风险: ```bash git fetch <github-remote> main # 如有未提交的更改,先 stash git stash # 仅在有 unstaged changes 时执行 git rebase <github-remote>/main # rebase 完成后恢复 stash git stash pop # 仅在之前执行了 stash 时 # rebase 改变了历史,需要 force push git push --force-with-lease <github-remote> <current-branch> ``` **如果 rebase 有冲突:** 1. 解决冲突文件 2. `git add <resolved-files>` 3. `git rebase --continue` 4. 重复直到 rebase 完成 5. `git push --force-with-lease` ### 4. 创建 Pull Request ```bash gh pr create --base main --title "PR标题" --body "描述" ``` 记录返回的 PR 编号(如 `#42`)。 ### 5. 等待并监控 CI Checks(关键步骤) **⚠️ 绝对不能跳过此步骤。必须确认 CI 全部通过后才能合并。** ```bash # 等待 CI 触发(GitHub Actions 有 10-30 秒延迟) sleep 30 # 等待所有 checks 完成 gh pr checks <pr-number> --watch --interval 15 --fail-fast ``