Git Rebase Vs Merge

Git Rebase Vs Merge

Short Version

  • Merge takes all the changes in one branch and merges them into another branch in one commit.

  • Rebase says I want the point at which I branched to move to a new starting point

So when do you use either one?

If you only ever rebase commits that have never left your own computer, you’ll be just fine. If you rebase commits that have been pushed, but that no one else has based commits from, you’ll also be fine. If you rebase commits that have already been pushed publicly, and people may have based work on those commits, then you may be in for some frustrating trouble, and the scorn of your teammates.

Best Practices

Follow the below best practices


In Feature
$ git pull
$ git rebase master
In Master
$ git pull
$ git rebase feature

Merge

  • Let’s say you have created a branch for the purpose of developing a single feature. When you want to bring those changes back to master, you probably want merge (you don’t care about maintaining all of the interim commits).

Rebase

  • A second scenario would be if you started doing some development and then another developer made an unrelated change. You probably want to pull and then rebase to base your changes from the current version from the repository.