简体   繁体   中英

Using git-flow, how to work rebase into the mix

I'm brand-new to rebasing. I'm used to the git-flow method, whereby I branch off our main/develop branch, do my work, open a pull request on github, and it's merged in and we move on. Works well.

Others are doing rebasing however, and I'd like to try it out. I've read up on it ( here for instance) and while I get the idea, one bit confuses me.

In git-flow, when I make my changes to my branch, I push that branch to the server and open a pull request. In a rebase, per the link above, I'm told to Periodically rebase your feature branch onto the current state of the destination branch ..

...and if I do that, what do I then push to github? The branch I've based onto, ( develop in my case)? As a git-flow guy that feels weird to me but maybe that's because I'm not used to it.

If there are other ideas on how to mentally shift from git-flow to doing rebasing I'm glad to hear of it as well.

Say your feature branch looks like this

* -- * -- A (master)
           \
            * -- * -- * (feature)

After some time, others have done work on master so that the history becomes

* -- * -- A -- B -- C -- D -- E (master)
           \
            * -- * -- * (feature)

The only thing that rebasing feature on to master does is to change when it appears you created the feature branch:

* -- * -- A -- B -- C -- D -- E (master)
                               \
                                * -- * -- * (feature)

By doing this periodically, you resolve any potential merge conflicts before they can pile up. If you merge master into feature periodically, you end up with lots of spurious merge commits in feature . With rebase, you avoid them, with the price being that you lose sight of when you initially branched feature from master . Keep in mind that you should only rebase if you haven't already pushed feature ; once you do, you have shared the history of feature with others and should not change it.

To periodically rebase your feature branch onto the current state of the destination branch (I'm assuming origin/master in this scenario), just do this from your feature branch:

git fetch origin            # Updates origin/master
git rebase origin/master    # Rebases current branch onto origin/master

An equivalent alternative:

git pull --rebase origin master

By doing so, you will keep your feature branch up to date with your origin/master branch. You can either merge it into your local master and push into origin/master or you can just push your rebased feature branch to the remote repository and just do a pull request. It really depends on your git workflow.

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