Skip to content

[Step 8] Avoid unnecessary merge with Rebase

Sam Lin edited this page Jan 18, 2018 · 2 revisions

This is a more an advanced topic. You don't use it day-to-day, but it is nice to know.

It is for moving the current feature branch to the latest parent branch.

so it would make this

become this

Here is a good reference if you decide to use this feature.

Explain Rebase vs Merge in 1 picture

  1. Currently we have 2 branches from master. Checkout master branch and edit .gitignore file and commit it as fix: update git ignore. It would be like this if you use SourceTree to review the graph of branches.

  2. Checkout the test branch and right-click on the branch and click Rebase Onto

  3. In Onto branch, select master and click Rebase. Since there is no conflict, it will commit the changes right away.

  4. the history will be like this in Sourcetree. The current branch looks like just branched out from the latest master commit.

Note:

  • if there are conflicts, you can either merge or abort this operation.

    command-line: git rebase --abort

  • if the process is done, use git reset --hard to the commit before rebase. ref

The whole process

Clone this wiki locally