简体   繁体   中英

How to sync multiple feature branches with master in git

My Scenario is this: From master branch to feature branch1, add changes to branch1 then create another branch from branch1 called branch2, then add changes to branch2.

If there are then pending changes to the master branch, what's the best approach to sync all branches with the master branch

Branch creation as follows Master to F1 then F1 to F2

You could rebase branch2 on top of master using --update-refs which is a newish option that will also update references that are setup in the path to branch2 , so should move the position of branch1 .

git checkout branch2
git rebase --update-refs master 

The kind of step by step way would be:

git checkout branch1
git branch temp # let's set a temporary marker before I move it
git rebase master
# now time to rebase branch2
git rebase --onto branch1 temp branch2
# remove the temporary branch if things went fine
git branch -D temp

The last rebase will rebase commits in the temp..branch2 range on top of branch1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM