简体   繁体   中英

Rebase local branch after pull from remote

I have a situation as the following where I have 2 local branches - one follows the other which follows the remote branch: A(origin/master)---B---C(topic)---D---E---F(master)

The topic branch follows origin/master branch. Master branch follows topic branch.

After some time the origin/master grows and we get the following:

A---G(origin/master)
 \
  \
    B---C(topic)---D---E---F(master)

So today, in order to rebase I'm doing the following:

(topic): git pull --rebase
(topic): git checkout master
(master): git pull --rebase
(master): git checkout topic
(topic):

I have this issue with several local branches (several topics ) and I wonder if there is some command that does all this rebasing for me without the need to checkout between branches. Does Such functionality exists?

Use:

git fetch

first, to update all your origin/* names after getting all new commits. Then use:

git rebase origin/master

to rebase your own personal, un-pushed topic branch to the updated origin/master .

(If you're annoyed that your own master gets behind, consider simply deleting your master branch. You can use the name origin/master to find their latest master any time you need to, and now that you do not have a master of your own, you won't feel the urge to update it.)

Important notes

If you have created a topic over on origin already, so that origin/topic exists, that this won't update your own origin/topic —well, unless someone else has done something on the Git over at origin . Then it will update your origin/topic , and then you'd best figure out what that someone-else did.

After running git rebase origin/master while on your own topic , you can use git push --force or git push --force-with-lease to send the rebased commits and update topic on the Git over at origin. If someone else is using the topic there, perhaps via some third Git's origin/topic , you may mess with them, just as they might have messed with you above.

Hence, if you have pushed origin/topic , make sure that everyone else agrees that it's OK for your to rebase your own topic and to git push --force (preferably -with-lease ).

(One common workflow is to use a third-party server like GitHub to store copies in case private Git repositories are on computers that crash or otherwise lose data. In this case, you may wish to push in-progress work: if everyone gets their own branch names here, and nobody uses anyone else's branches, this "get permission to update a shared branch" problem goes away, because these branches aren't shared, even though everyone can see everyone else's.)

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