Pull Is Fetch Plus Integrate
git pull does two things in a row: it fetches from the remote, exactly like
git fetch, and then integrates the remote branch into your current branch.
When nobody else is working on your branch, that second step is a
fast-forward and you barely notice it. When you and a teammate have both
committed, it needs a decision.

When Branches Have Diverged
If both your branch and the remote have new commits, they have diverged.
Git could combine them with a merge or with a rebase, and the results look
different, so it does not guess. A plain git pull stops:
hint: You have divergent branches and need to specify how to reconcile them.
...
fatal: Need to specify how to reconcile divergent branches.
The fetch has already happened, so git status now reports the divergence.
Nothing else has changed. Choose how to integrate:
git pull --no-rebase # merge: keeps both lines of history, adds a merge commit
git pull --rebase # rebase: replays your unpushed commits on top
Both are fine for commits you have not pushed yet. Rebasing only touches your own unpushed commits, so it is safe here and gives a straight history; merging records exactly what happened.
Some older versions of Git do not stop here: they print a warning about
pull.rebase and merge. If that happens, carry on as if you had chosen
--no-rebase.
Choosing a Default
To stop being asked, record your choice for the repository:
git config pull.rebase false # pulls merge
git config pull.rebase true # pulls rebase
Add --global to apply it to every repository. Teams often agree on one
choice. The command-line options above still override the setting for a single
pull.
Conflicts During a Pull
If the integration step conflicts, you resolve it exactly as in the merge and
rebase lessons. After a merge-style pull, finish with git merge --continue;
after a rebase-style pull, with git rebase --continue. If you want to back
out, git merge --abort or git rebase --abort returns you to where you were
before the integration. Then push, so your teammate can pull the result.
Exercise: Integrate Diverged Work
Asha and Ravi both edit the meeting line in README.md. You will see the pull
refuse, merge with a conflict, and bring both clones back in step.
Starting state: Git configured as in the configuration lesson. You will rebuild the team practice set.
-
Rebuild the practice set:
cd ~/git-practice rm -rf team mkdir team cd team git init --bare -b main shared.git git clone shared.git asha cd asha git config user.name "Asha Rao" git config user.email "asha@example.com" cat > README.md <<'EOF' # Team notes We meet on Mondays. Bring your laptop. EOF git add README.md git commit -m "Add team notes" git push -u origin main cd .. git clone shared.git ravi cd ravi git config user.name "Ravi Kumar" git config user.email "ravi@example.com" cd .. -
As Asha, move the meeting to Tuesday and share it:
cd asha cat > README.md <<'EOF' # Team notes We meet on Tuesdays. Bring your laptop. EOF git commit -am "Move meetings to Tuesday" git push -
As Ravi, add a time to the same line, not knowing about Asha's change:
cd ../ravi cat > README.md <<'EOF' # Team notes We meet on Mondays at 10:00. Bring your laptop. EOF git commit -am "Add meeting time" -
Try to pull:
git pull git statusGit fetches, then stops with
Need to specify how to reconcile divergent branches.git statussays Ravi's branch andorigin/mainhave diverged, with 1 and 1 different commits each. -
Choose to merge:
git pull --no-rebase git status cat README.mdThe merge reports
CONFLICT (content): Merge conflict in README.md. In the file, Ravi's line follows<<<<<<< HEADand Asha's comes after=======. The closing marker shows the ID of Asha's commit. -
The meeting is now on Tuesday, and Ravi's time still applies. Resolve, finish the merge and share it. Save and close the editor when it opens:
cat > README.md <<'EOF' # Team notes We meet on Tuesdays at 10:00. Bring your laptop. EOF git diff --check git add README.md git merge --continue git push -
As Asha, catch up and compare:
cd ../asha git pull git log --oneline --graphAsha's pull fast-forwards, because she has nothing new. Her graph shows both commits joined by Ravi's merge commit, and
README.mdreadsWe meet on Tuesdays at 10:00. -
Choose a default in both clones, so future pulls merge without asking:
git config pull.rebase false cd ../ravi git config pull.rebase false
Success: both clones show the same history, ending with Ravi's merge
commit, and README.md contains the combined line.
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
Need to specify how to reconcile divergent branches | Both sides have new commits and no choice is set | Use --no-rebase or --rebase, or set pull.rebase |
Git merged without asking, with a warning about pull.rebase | An older Git version | Continue from the conflict as in step 5 |
CONFLICT | Both sides changed the same lines | Resolve, git add, then git merge --continue or git rebase --continue |
Your local changes to the following files would be overwritten by merge | Uncommitted edits in a file the pull changes | Commit or stash them, then pull again |
| The push in step 6 is rejected | The merge was not finished | Check git status, finish it, then push |
- Keep the practice set for the next lesson.
Independent task: try the rebase style, with changes that do not conflict. As Asha, add a line and share it; as Ravi, start a new file and commit it:
cd ../asha
cat >> README.md <<'EOF'
Agenda goes out on Fridays.
EOF
git commit -am "Mention the agenda"
git push
cd ../ravi
cat > notes.md <<'EOF'
# Meeting notes
EOF
git add notes.md
git commit -m "Start meeting notes"
As Ravi, integrate Asha's commit by rebasing for this one pull, even though
pull.rebase is set to false, then share your commit. Show that the history
has no new merge commit.
Check Your Understanding
- You see
fatal: Need to specify how to reconcile divergent branches.What has happened, and what are your options? - Has anything in your branch or files changed after that message?
Answer and Reasoning
Independent task
git pull --rebase
git push
git log --oneline --graph
The command-line --rebase overrides the pull.rebase setting for this pull.
Ravi's "Start meeting notes" is replayed on top of Asha's "Mention the agenda",
so the newest part of the graph is a straight line with no new merge commit,
and the push succeeds.
Understanding check
- Your branch and the remote branch have both gained commits, and Git will
not choose between merging and rebasing for you. Run
git pull --no-rebaseto merge orgit pull --rebaseto replay your unpushed commits, or setpull.rebaseto make that choice the default. - Only the fetch happened:
origin/mainwas updated. Your branch, staging area and files are untouched until you integrate.