What is the difference between a merge and a rebase?

About

merge and rebase are two command that are designed to integrate changes between two branches

They have one difference:

Example

Imagine this commit history (log) 1) with a remote and a local branch where the commit in the remote branch will be integrated into the local branch.

- A - B - C - D - remote HEAD
    \
      E - F - G - local HEAD

After a merge, the commit history (log) will look like:

- A - B - C - D - remote HEAD
    \                         \
      E - F - G - local HEAD - new local HEAD

After a rebase, the commit history (log) will look like:

- A - B - C - D - remote HEAD - E' - F' - G' - local HEAD'

Advantage / Disadvantage

There is a trade-off:

  • The advantage of a rebase is that the history is easier to follow.
  • The disadvantage is that the code in commit G may not work nicely with the code in commit B.





Discover More
Git - Merge

Merge is a git merge tool that is designed to integrate changes from one branch into another branch It joins two or more branch together (ie development histories) The pull command is a wrapper that...
Git - rebase

rebase is designed to integrate changes from one branch into another branch. Imagine this commit history (log) with a remote and a local branch where the commit in the remote branch will be integrated...



Share this page:
Follow us:
Task Runner