merge-or-rebase-a-branch

Owner: Arthur Levoyer

Prerequisites

    Have git-cli installed

Context

Let's say, you are currently working on your own my-feature branch and someone from your team is merging new commits into the master branch which you would like to use. You have two different possibilities to incorporate them to your my-feature branch.
image

Steps

    1.
    First approach: Merge a branch
Merge the master branch into the feature branch by entering following:
    git checkout my-feature
    git merge master
    It gives you a new “merge commit” in the feature branch that ties together the histories of both branches.
It's nice because it is a non-destructive operation but if your master branch is very active, you might quickly have a new commits including a lot of changes and this will pollute your history quite a lot.
image
    1.
    Second approach: Rebase a branch
    2.
    git checkout my-feature
    3.
    git rebase master
The difference with the merge solution above, it that it will create new commits into your `my-feature` for each commits in `master` and give you a much cleaner project history.
On the other hand, a very unwanted situation might occur if you do not follow the Golden Rules of Rebasing
image
Source: atlassian.com
Last modified 3yr ago