Pull Changes
Goal: Bring a remote's new commits into your current branch with git pull, and choose between merging and rebasing.
git pull is two commands in one: a git fetch, then a git merge (or a git rebase) of the upstream branch into the branch you are on.
That second half is the part that moves your files, so everything you know about merging — fast-forwards, merge commits, conflicts — applies unchanged.
Pull is fetch plus integrate
Running git pull on main is equivalent to:
git fetch origin— download and moveorigin/maingit merge origin/main— join those commits into yourmain
If your branch has no commits of its own, the merge is a fast-forward: your main label simply slides along to origin/main, with no merge commit. That is the quiet, everyday case.
Pulling onto a branch that has moved too
Step 1 of 3
Your main has one commit the server does not; the server has one you do not. The branches have diverged, and a fetch has already shown you both.
Step 1 of 3. Your `main` has one commit the server does not; the server has one you do not. The branches have diverged, and a fetch has already shown you both.
Merge or rebase when pulling?
git pull
- Merges the upstream branch in
- Adds a merge commit when both sides moved
- History shows exactly what happened
git pull --rebase
- Replays your commits on top of theirs
- No merge commit, straight history
- Rewrites your unpushed commits
git pull --ff-only
- Refuses unless it is a clean fast-forward
- Stops and lets you decide
- The safest default for a shared branch
An everyday fast-forward pull
$ git pull
From https://github.com/acme/weather-app 1b7e55c..8d4c21e main -> origin/main Updating 1b7e55c..8d4c21e Fast-forward src/header.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
The first two lines are the fetch; the rest is the merge. "Fast-forward" means your branch had nothing of its own, so Git only had to move the label and update the files.
