基于未合并分支开发新功能时的Git分支处理方法
Can I develop feature-b based on feature-a while its merge request is pending?
Absolutely! This is a super common workflow in team development—especially when feature-b depends on code from feature-a—and it works perfectly even while feature-a's merge request (MR) is still in a pending state. Here's a clear, step-by-step guide to pull this off:
- First, make sure your local
feature-abranch is up to date with the remote version (in case you or a teammate pushed changes after your initial MR):git checkout feature-a git pull origin feature-a - Create your new
feature-bbranch directly from the updatedfeature-a:git checkout -b feature-b - Now you can start developing feature-b just like you would any other branch. Once you're done with changes, stage and commit your work:
git add . git commit -m "Add core functionality for feature-b" - Push the new
feature-bbranch to the remote repository:git push origin feature-b - You can even open a merge request for
feature-bright away! Just make sure to note in the MR description that it depends on the pending MR forfeature-a—this helps your team know the order of operations for merging.
A quick heads-up for later:
If feature-a gets updated (e.g., you make changes based on MR feedback and push them), you'll want to sync those updates to feature-b to avoid conflicts down the line. Here's how:
- Switch back to
feature-aand pull the latest changes:git checkout feature-a git pull origin feature-a - Switch to
feature-band merge (or rebase) the updatedfeature-ainto it:- Merge (keeps a clear merge history):
git checkout feature-b git merge feature-a - Rebase (rewrites
feature-b's commits to sit on top of the latestfeature-a, resulting in a cleaner linear history):git checkout feature-b git rebase feature-a
feature-bto remote, you'll need to force push after rebasing (usegit push origin feature-b --force-with-leaseto be safe, as it avoids overwriting others' work). - Merge (keeps a clear merge history):
内容的提问来源于stack exchange,提问作者GluePear
相关产品推荐
相关产品推荐

