Skip to main content

Merge - Rebase - Squash

When should you use either of them?


Merge

merge.gif
Source: https://www.gitkraken.com/learn/git/git-merge (Last accessed 22.03.2023)

Merging is used to merge two branches and preserve their history. It also makes it easier to undo mistakes.


Rebase

rebase.gif
Source: https://www.gitkraken.com/learn/git/git-rebase (Last accessed 22.03.2023)

Rebasing can be beneficial in feature branches. Dev --> feature/<feature-name>

Rabase will rewrite commit history so please don't use it on shared branches like dev and main.


Squash

commits-to-be-squashed.gif
Source: https://www.gitkraken.com/learn/git/git-squash (Last accessed 22.03.2023)

Squash can be used to condense a lot of commits into one. This can be useful if want to merge dev into main and you have 50 commits.