git merge and git rebase #1109
-
|
what is the difference between git merge and git rebase. When would you use one over the other? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
git merge After (rebase feature onto main): You're working on a shared/public branch that others are also using. You're working on a local/private feature branch and just want to incorporate upstream changes. |
Beta Was this translation helpful? Give feedback.
git merge
What it does: Creates a new merge commit that joins two branches together. The feature branch's history is preserved intact, and a merge commit records that the branches were combined.
History: Non-linear — you see the actual branching and merging pattern.
Safety: Non-destructive. Existing commits on either branch are never altered.
text
A---B---C feature
/
D---E---F-------G main ← merge commit G
git rebase
What it does: Takes the commits from your feature branch and replays them on top of the target branch, rewriting history as if you started working from the latest point.
History…