# Merge - Rebase - Squash

## When should you use either of them?

---

### Merge

[![merge.gif](https://bookstack.hopeless-cloud.xyz/uploads/images/gallery/2024-02/merge.gif)](https://bookstack.hopeless-cloud.xyz/uploads/images/gallery/2024-02/merge.gif)  
Source: [https://www.gitkraken.com/learn/git/git-merge](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](https://bookstack.hopeless-cloud.xyz/uploads/images/gallery/2024-02/rebase.gif)](https://bookstack.hopeless-cloud.xyz/uploads/images/gallery/2024-02/rebase.gif)  
Source: [https://www.gitkraken.com/learn/git/git-rebase](https://www.gitkraken.com/learn/git/git-rebase) (Last accessed 22.03.2023)

Rebasing can be beneficial in feature branches. Dev --&gt; feature/&lt;feature-name&gt;

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

---

### Squash

[![commits-to-be-squashed.gif](https://bookstack.hopeless-cloud.xyz/uploads/images/gallery/2024-02/commits-to-be-squashed.gif)](https://bookstack.hopeless-cloud.xyz/uploads/images/gallery/2024-02/commits-to-be-squashed.gif)  
Source: [https://www.gitkraken.com/learn/git/git-squash](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.