You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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-branch with 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:
    1. Open your code editor and resolve the conflicting line-by-line.
    2. Stage the resolved changes:
      git add .
      
    3. Continue the rebase process:
      git rebase --continue
      
    Repeat this until all conflicts are fixed and the rebase completes successfully.
  • Since rebasing rewrites your branch's commit history, you'll need to force-push the updated branch. Use --force-with-lease (safer than plain --force because 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:
    1. Resolve the conflicts in your editor.
    2. Stage the resolved files:
      git add .
      
    3. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:21:18