What Is The Difference between git merge and git rebase?

Question
What is the difference between git merge and git rebase?

Answer
git merge takes code from one branch and copies it into another branch. One branch will prevail to the extent there are conflicts. (The details of the syntax are beyond the scope of this solution. The git merge operation can be done in a GUI (e.g., via BitBucket).) The published source code would usually change.

git rebase takes code from a committed branch and overwrites your local branch. git rebase brings down code with the trunk code always prevailing. The published source code does not change.

git merge is for committing code upstream and git rebase is for bring new code downstream. If production is the most upstream you can go and development is the most downstream you can go, the public Git repository holds code. As you develop a new feature, you may find another developer committed code for something you were working on. You may want to bring that change upstream back down into development. This way when you integrate your code, you can manually reconcile any potential conflicts.

"The golden rule of git rebase is to never use it on public branches." (Taken from this link.)

git merge operations are usually for making public your code. git rebase is usually for getting a new baseline to develop from.

If you want to learn more about the differences between the two, see these postings:
https://www.atlassian.com/git/tutorials/merging-vs-rebasing
https://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge

Leave a comment

Your email address will not be published. Required fields are marked *