About rebase2main
rebase2main is a Git workflow skill for rebasing the current development branch onto main, pushing main to origin, and returning to the original branch. It checks the branch and working-tree state first, and stops for dirty changes or rebase conflicts.
Key features
- 01Records the current branch
- 02Requires a clean working tree
- 03Rebases the branch onto main
- 04Pushes main without force
- 05Stops on conflicts or push failure
Use cases
- 01Updating main with commits from a development branch
- 02Checking repository state before a branch update
- 03Avoiding force pushes during the update
- 04Handling rebase conflicts before proceeding
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ ruan-cat/ monorepo --skill rebase2mainAfter installing, type/rebase2mainin Claude Code to confirm it loaded.
Details
From the project READMERebase to Main
将当前开发分支的提交以 rebase 方式同步到 main 分支,推送远端,再切回原分支。
工作流程
-
记录当前分支名称
git branch --show-current将结果保存,后续用于切回。如果当前已在 main 分支,提示用户并终止。
-
确认工作树干净
git status如果存在未提交的变更,提示用户先处理(提交或暂存),不要继续。
-
切换到 main 分支
git checkout main -
将 dev 的提交 rebase 到 main
git rebase <原分支名>如果出现冲突,停止并告知用户需要手动解决。
-
推送 main 到远端
git push origin main使用普通 push,不使用
--force。如果 push 失败,告知用户原因。 -
切回原分支
git checkout <原分支名>
注意事项
- 不使用
--force推送,保证远端历史安全 - 如果 rebase 过程中出现冲突,立即停止并告知用户
- 执行前必须确认工作树干净(无未提交变更)
Comments
Markdown supported