merge-or-rebase-a-branch
Last updated
Last updated
Have git-cli installed
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.
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.
Second approach: Rebase a branch
git checkout my-feature
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
Source: atlassian.com