Synchronize the commits of the current development branch to the main branch via rebase, push to the remote, then switch back to the original branch.
Workflow
-
Record the current branch name
git branch --show-currentSave the result for later use when switching back. If currently already on the main branch, notify the user and terminate.
-
Confirm the working tree is clean
git status
If there are uncommitted changes, prompt the user to handle them first (commit or stash), and do not continue.
-
Switch to the main branch
git checkout main -
Rebase dev's commits onto main
git rebase <原分支名>If conflicts occur, stop and inform the user that they need to be resolved manually.
-
Push main to the remote
git push origin mainUse a normal push, do not use
--force. If the push fails, inform the user of the reason. -
Switch back to the original branch
git checkout <原分支名>
Notes
- Do not use
--forcepush, to ensure remote history safety - If conflicts occur during the rebase, stop immediately and inform the user
- Before executing, must confirm the working tree is clean (no uncommitted changes)