Merge vs Rebase

Reading Time: 3 minutes
Merge vs Rebase

In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase. When comparing Git rebase vs merge, both actions can be used to combine file changes from one branch to another, but there are associated benefits and drawbacks to both.

In this article we will be looking about git rebase and git merge and how they differ with quick example.

Git Merge

In Git, the merging is a procedure to connect the forked history. It joins two or more development history together. The git merge command facilitates you to take the data created by git branch and integrate them into a single branch. Git merge will associate a series of commits into one unified history. Generally, In simple word, git merge is used to combine two branches.

suppose I am working on a branch PRO-#535-updated-BankAccount and fix the issues as per requirement and this branch is now ready to be merge with master branch so all we have to do is check out the branch you wish to merge into and then run the command to merge our branch

How to do git merge

git merge <branch name>


While Git can perform most integrations automatically but some changes will result in conflicts that have to be solved by the user and we can go through to understand merge-conflict.

Before applying outside changes, you should get your own work in good shape and committed locally, so it will not be clobbered if there are conflicts. 

Git Rebase

In Rebase we combine a series of commits or one commit to a new commit. As It allows you to rewrite the commit from one branch to another branch.

suppose I am working on branch PRO-#535-updated-BankAccount and work is not finished yet and Changes have been made to the master branch that you want to incorporate into your code. but as our code is not ready, merging a branch is not a choice here.

 I can copy the history of the master branch to PRO-#535-updated-BankAccount . This will ensure your branch reflects all the history the master branch has accrued. Rebase is beneficial because it will maintain the history of your project. Developers will be able to easily see how your changes have affected the development of a project.

How to do git Rebase

git checkout <branch name>
git rebase origin/master

Here are few articles that will help you in learning few more things in Git:

  2. Git Rebase vs Pull

Thanks for reading!!!

Written by 

Anuradha Kumari is a Software consultant at Knoldus Inc. She is a tech enthusiast and likes to play with new technology and writing tech blogs.