Git merge and Git rebase
git merge combines two branches by creating a merge commit that preserves both histories—e.g., if main advanced while you worked on feature,
git checkout main && git merge feature
keeps the branch topology and shows exactly when integration happened.
so use it for shared/public branches, release branches, and when you want an auditable, non-destructive record;
avoid it mainly when noisy merge commits clutter a small local feature branch.
git rebase instead replays your commits onto a new base to produce a linear history—e.g.,
git checkout feature && git rebase mainmoves your feature commits on top of the latest main, after which main can fast-forward so use it to tidy up local, unpushed work before opening a pull request or syncing a private branch; never rebase commits that others have already pulled or branches like main, because rewriting shared history forces everyone to recover and can cause confusing duplicate commits. @fullstackCampp
24 11月, 12:04
