Understand the difference between Git merge and Git rebase commands.
What are the differences?
When we ๐ฆ๐๐ซ๐ ๐ ๐๐ก๐๐ง๐ ๐๐ฌ from one Git branch to another, we can use โgit mergeโ or โgit rebaseโ. The diagram below shows how the two commands work.
This creates a new commit Gโ in the main branch. Gโ ties the histories of both main and feature branches.
Git merge is ๐ง๐จ๐ง-๐๐๐ฌ๐ญ๐ซ๐ฎ๐๐ญ๐ข๐ฏ๐. Neither the main nor the feature branch is changed.
Git rebase moves the feature branch histories to the head of the main branch. It creates new commits Eโ, Fโ, and Gโ for each commit in the feature branch.
The benefit of rebase is that it has ๐ฅ๐ข๐ง๐๐๐ซ ๐๐จ๐ฆ๐ฆ๐ข๐ญ ๐ก๐ข๐ฌ๐ญ๐จ๐ซ๐ฒ.
Rebase can be dangerous if โthe golden rule of git rebaseโ is not followed.
Never use it on public branches!