Git Merge and Rebase: The Dance of Branches and the Rebirth of Commits
Merge and rebase are two different approaches to get changes from one branch to another.
Let's assume we are trying to get the latest changes from the main
to a feature branch
we are currently developing.
Merge
Takes the latest changes from the main
and creates a new commit in the feature branch
.
Commands:
git checkout feature-branch
git merge main
Pros: | Cons: |
Preserves the whole commit history. | Can get messy with more details. |
Rebase
Changes the base of a feature branch to the latest commit on the main
and then places the feature branch
changes from there.
Commands:
git checkout feature-branch
git rebase main
Pros: | Cons: |
Linear and cleaner commit history. | Reduced traceability |