Git Foundations / Work With a Remote

Pull and integrate changes

Lesson 25 of 33. Open to read. No account needed.

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.

Step 1: git fetch downloads new commits and updates origin/main. Step 2: Git integrates origin/main into your branch. If only the remote has new commits, it fast-forwards. If both sides have new commits, by default Git stops and asks you to choose --no-rebase to merge or --rebase to replay your commits on top. The choice can be saved per repository with git config pull.rebase.

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.

  1. 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 ..
    
  2. 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
    
  3. 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"
    
  4. Try to pull:

    git pull
    git status
    

    Git fetches, then stops with Need to specify how to reconcile divergent branches. git status says Ravi's branch and origin/main have diverged, with 1 and 1 different commits each.

  5. Choose to merge:

    git pull --no-rebase
    git status
    cat README.md
    

    The merge reports CONFLICT (content): Merge conflict in README.md. In the file, Ravi's line follows <<<<<<< HEAD and Asha's comes after =======. The closing marker shows the ID of Asha's commit.

  6. 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
    
  7. As Asha, catch up and compare:

    cd ../asha
    git pull
    git log --oneline --graph
    

    Asha's pull fast-forwards, because she has nothing new. Her graph shows both commits joined by Ravi's merge commit, and README.md reads We meet on Tuesdays at 10:00.

  8. 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 seeLikely causeNext step
Need to specify how to reconcile divergent branchesBoth sides have new commits and no choice is setUse --no-rebase or --rebase, or set pull.rebase
Git merged without asking, with a warning about pull.rebaseAn older Git versionContinue from the conflict as in step 5
CONFLICTBoth sides changed the same linesResolve, git add, then git merge --continue or git rebase --continue
Your local changes to the following files would be overwritten by mergeUncommitted edits in a file the pull changesCommit or stash them, then pull again
The push in step 6 is rejectedThe merge was not finishedCheck git status, finish it, then push
  1. 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

  1. You see fatal: Need to specify how to reconcile divergent branches. What has happened, and what are your options?
  2. 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

  1. 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-rebase to merge or git pull --rebase to replay your unpushed commits, or set pull.rebase to make that choice the default.
  2. Only the fetch happened: origin/main was updated. Your branch, staging area and files are untouched until you integrate.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy