All you need to know about Git Merge vs Git Rebase in Examples

Artem Diashkin
LITSLINK
Published in
7 min readAug 8, 2020

--

What is the main idea behind git merge and rebase commands, and how it works behind the scene. All you need to know for being confident in using it.

In Git, there are two main ways to integrate changes from one branch into another: git merge and the rebase commands.

Before we will talk about differences in merge and rebase commands, we need to have an understanding of what branches are:

Branch — is just a reference to a commit.

Let’s imagine that we have initialized a new git project with three branches: master, first and second.

If we will use git cat-file <commit-sha> -p command to each commit, we will see that commits have a parent (not master branch, obviously), and our “branches” are just references to those commits.

git cat-file <SHA> -t // type
git cat-file <SHA> -p // pretty printing
p —> parent

--

--