Video in progress
How does `git pull --rebase` differ from a plain `git pull`, and why do many people prefer it?
A plain pull merges the server's changes and often creates an unneeded "Merge branch 'main' of ..." commit. --rebase puts your local commits back on top of the server's, and the history stays a straight line.
📖 Answer
The situation: you made two local commits, and in the meantime a colleague pushed one commit to main.
plain pull: A---B---X---M (M is a meaningless merge commit)
\ /
C---D
pull --rebase: A---B---X---C'---D'
C' and D' are new copies of your commits (with different hashes). Since they have not been pushed yet, this harms nobody.
To make it permanent:
git config --global pull.rebase true
If there is a conflict, the rebase stops at each commit: you fix it, git add, git rebase --continue. If you get tangled up, git rebase --abort returns everything to the starting state.
One exception: if your local branch has merge commits you made yourself, a rebase flattens them. This is rare, but good to know.
Sign up to mark studied questions and save your progress.