Rebase
Rebase and merge both integrate changes from one branch into another, but they work differently:| Merge | Rebase | |
|---|---|---|
| Commit hashes | Unchanged — history is not rewritten | Updated — commits are re-applied on top of the target branch |
| History | Preserves the original branch structure with a merge commit | Produces a linear, cleaner history |
When to rebase
Suppose Developer A is working on thedevelop branch while the team continues pushing commits to main. Developer A wants to keep develop up to date with main without creating a merge commit.
Instead of merging:
develop on top of main:
develop commits on top of the latest main commits, resulting in a linear history as if the develop work had started from the current tip of main.
Interactive rebasing
Interactive rebase lets you modify the Git history before applying it — for example, combining multiple commits into one (squashing). Suppose you have these commits:squash (or s) instead of pick. After saving, they are combined into one commit.
Result:
Cherry-pick
Cherry-pick lets you apply a specific commit from one branch onto another branch, without merging all other changes from that branch.When to cherry-pick
Suppose Developer A is onmain and wants only the changes from the "docs: edit second story" commit on develop.
Cherry-pick only brings in the changes from the selected commit, not the full branch history. If you encounter merge conflicts, resolve them manually and complete the cherry-pick.