(ง •̀_•́)ง Ming's blog

What is rebase?

Imagine you and a co-worker are in charge of tickets A and B for a new feature. Let’s say it is on the feature branch. Your co-worker completed the ticket before you do and this is how the branch looks like when you are ready to submit your PR:

branching

In your local history, your work has the index(or SHA) of 2 but on the feature branch 2 is B.

We want to maintain a linear commit history and avoid as many merge conflicts as we can. In other words, we want to achieve something like this:

merging

We do that with rebase.

How to rebase(with SourceTree)

  1. Make sure your local copy of feature is up to date. Do a fetch and pull.
  2. Check out your ticket A branch. Right-click on the local feature branch and select “rebase onto feature branch”.
  3. Now if you do a git status, you should see something like “10↓1↑”. The 10 is how many changes you are behind the feature branch and the 1 commit you have is to modify your SHA from 2 to 3.
  4. SourceTree doesn’t allow a force push so in your terminal, do git push -f.

And that’s it! You placed your code nicely in git.

#git