Pull with Rebase
Pull with Rebase When Your Branch Is Out of Date
After this page you can update a local branch from a remote without a merge commit from git pull.
pull is fetch plus integrate
git pullmeans git fetch then, by default, a merge of @{u} (the upstream) into HEAD. If both you and the remote moved, you get a merge commit that only exists because you pulled.
after fetch, both moved
origin/main A ← B ← C ← G
local main A ← B ← C ← D ← E
git pull (merge) A ← B ← C ← G ← M
D ← E ↗
git pull --rebase A ← B ← C ← G ← D' ← E'
Chapter 2 set:
git config --global pull.ff onlyThen git pull fails instead of merging. You choose:
git pull --rebase
# or
git fetch
git rebase @{u}--rebase copies your local-only commits onto the updated upstream, then fast-forwards your branch name.
When this is the right shape
You committed two fixes on main locally. Someone else pushed to origin/main. git pull --rebase replays your two fixes on top of theirs. History stays linear. Conflicts are per commit (previous page).
When to merge instead
You want a merge commit that records “I integrated upstream at this point.” Feature branches that you share, or main policies that require merge commits, use git pull --no-rebase or an explicit git merge.
Set it for this branch only
git config pull.rebase true # this repo
git config --global pull.rebase true # every repo (overrides pull.ff only)This book leaves pull.ff only as the global default so a surprise pull fails closed. Type --rebase when you mean it, until the habit is there.
After a rebase pull
git status
git log --oneline --graph --decorate -12Your branch is ahead of 'origin/main' by N commits means you still need git push. If you had already pushed the old hashes, you need a force-with-lease (chapter 11).