pr merge strategies

pr merge strategies

merge commit vs squash vs rebase — what each does and when to use it

pr merge strategies

three ways to merge a PR. each has a different effect on history.

merge commit

copy
main: A - B - M
              |
feat:   C - D

preserves the branch history. creates an explicit merge commit. good when you want to see that a feature landed as a unit. can get noisy on busy repos.

squash and merge

copy
main: A - B - CD

squashes all your commits into one and puts it on main. clean history, but you lose the individual commit context. good for small features or when your branch commits are a mess of "wip" and "fix typo".

rebase and merge

copy
main: A - B - C' - D'

replays each commit from your branch onto main individually. linear history, no merge commit. looks like everything was developed on main. good if your commits are clean and meaningful on their own.

when to use which:


good habits

copy
# wrong
git switch main
# make changes
git commit -m "quick fix"
 
# right
git switch -c fix/whatever
# make changes
git commit -m "fix whatever"
# open a PR
copy
git pull --rebase
git push
copy
# bad
git commit -m "update styles"
 
# better
git commit -m "increase font size on mobile — was unreadable at 12px"