Rebase \ Merge
Rebase and merge are two different strategies used to integrate changes from one branch into another
Rebase \ Merge
Rebase and merge are two different strategies used to integrate changes from one branch into another in Git. They serve similar purposes but do so in distinct ways, and understanding their differences is crucial for effective version control.

Merge
- A merge takes the contents of a source branch and integrates them into a target branch. It creates a new commit, called a “merge commit,” that combines the histories of both branches.
Assume you have the following commit history:
main: A --- B --- C
feature: \--- D --- E
A,B, andCare commits on themainbranch.DandEare commits on thefeaturebranch, which diverged frommainafter commitB.
When you merge the feature branch into main, Git creates a merge commit M:
main: A --- B --- C --- M
\ /
feature: D --- E
Pros:
- Preserves the complete history of all changes, including the context of when and why branches diverged and merged.
- Maintains the chronological order of commits.
Cons:
- The history can become cluttered with many branches and merge commits, making it harder to read.
Rebase
- Rebase re-applies commits from a source branch onto a target branch. It essentially moves the base of the feature branch to a new commit point on the target branch. Rebase rewrites commit history, creating new commits for the rebased changes.
- The feature branch commits will always appear as the latest additions, making it look as if they were developed on top of the most recent changes in the base branch. This is useful for integrating a feature with the latest codebase and for maintaining a clean, linear commit history.
Assume you have the following commit history:
main: A --- B --- C
feature: \--- D --- E
Rebasing the feature branch onto main changes the history to:
main: A --- B --- C --- D' --- E'
D' and E' are new commits that represent the changes from D and E, but based on commit C.
Pros:
- Creates a linear history, which can make it easier to understand the project history and track changes.
- Avoids merge commits, resulting in a cleaner commit history.
Cons:
- Rewrites history, which can be dangerous if not handled carefully, especially with public branches.
- Can be complex to resolve conflicts if they occur during the rebase.
Choosing Between Merge and Rebase
Use Merge:
- When you want to preserve the historical context of commits and clearly show the merging of branches.
- For integrating long-lived branches or when working with shared/public branches where rebasing could cause confusion.
Use Rebase:
- When you want a cleaner, linear project history without extra merge commits.
- When working on a private branch that hasn’t been shared yet, making it safe to rewrite history.
Visual Comparison
Merge:
A---B---C---M
\ /
D----E
Rebase:
main: A --- B --- C --- D' --- E' --- F' --- G' --- H'
feature1: |-----D------E------F
feature2: |------G------H
Both merge and rebase have their places in a Git workflow. The choice between them often depends on the team’s preferences, the project’s requirements, and the need for a clear and maintainable history.
메타데이터
- post_id
- 6894d25830ae
- slug
- rebase-merge-6894d25830ae
- url
- https://medium.com/@sskmal/rebase-merge-6894d25830ae
- canonical_url
- https://medium.com/@sskmal/rebase-merge-6894d25830ae
- author_url
- https://medium.com/@sskmal
- status
- ok
- fetched_at
- 2026-06-27 18:20:27