GitLab中如何基于master新变更继续原有分支开发
How to Continue Developing Your Feature Branch with Latest Master Changes in GitLab
Hey there! Let me break down the two most common, reliable ways to sync your feature branch with the updated master branch so you can pick up your development work smoothly.
Option 1: Rebase for a Clean, Linear Commit History
This is the go-to choice if you're the only one working on the feature branch and want a tidy, linear commit log without extra merge commits.
- First, switch back to your feature branch (replace
your-feature-branchwith your actual branch name):git checkout your-feature-branch - Run the rebase command to apply all your branch's commits on top of the latest master changes:
git rebase master - If conflicts pop up:
- Open your code editor and resolve the conflicting line-by-line.
- Stage the resolved changes:
git add . - Continue the rebase process:
git rebase --continue
- Since rebasing rewrites your branch's commit history, you'll need to force-push the updated branch. Use
--force-with-lease(safer than plain--forcebecause it prevents overwriting changes others might have pushed to the same branch):git push --force-with-lease origin your-feature-branch
Option 2: Merge for Explicit Merge History
Use this if your team prefers to keep clear merge markers, or if multiple people are collaborating on the feature branch (merge doesn't rewrite commit history, so it's less risky for shared branches).
- Switch back to your feature branch:
git checkout your-feature-branch - Merge the latest master changes into your branch:
git merge master - If conflicts occur:
- Resolve the conflicts in your editor.
- Stage the resolved files:
git add . - Complete the merge by creating a merge commit (Git will auto-populate a message, but you can edit it to add context if needed):
git commit
- Push the merged branch to GitLab (no force push needed here):
git push origin your-feature-branch
Quick Pro Tips
- Always test your code after resolving conflicts to make sure nothing breaks unexpectedly!
- If your team has a standardized workflow (rebase vs merge), stick to that to keep everyone aligned.
内容的提问来源于stack exchange,提问作者sherman
相关产品推荐
相关产品推荐

