CodeBlanks Logo Icon CodeBlanks

fetch vs pull

Learn the difference between fetch and pull.

The Difference Between Fetch and Pull

git fetch downloads new commits and reference information from the remote repository, but does not automatically change your current branch. git pull integrates the downloaded changes into your current branch.

git fetch origin
git pull origin main

You can use fetch when you want to inspect changes before integrating them.

Inspecting Changes After Fetch

After git fetch, you can inspect the updated state of a remote branch. For example, origin/main represents the main branch on the remote repository.

git fetch origin
git log HEAD..origin/main --oneline

The second command lists remote commits that are not present in your local branch. This lets you see what arrived before integrating it.

Practice Fetch First, Then Inspect

Download information from the remote repository using fetch. Then list remote commits that are missing from your local branch in short format.

Starter code

terminal
print("Uzak bilgiler alınıyor")

Sample solution

terminal
git fetch origin
git log HEAD..origin/main --oneline
print("İnceleme tamamlandı")

Expected output

Uzak bilgiler alınıyor
İnceleme tamamlandı

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command should you use if you want to download remote changes without integrating them into your current branch yet?

  • git fetch Correct answer
  • git pull
  • git merge
  • git commit

Explanation: Correct. fetch downloads remote information but does not change your current branch through an integration operation.

2 Download Remote Information with Fetch

Question
git ____ origin
Answer
git fetch origin

Explanation: fetch downloads remote commit and reference information; it does not automatically merge them into your current branch.

3 Fetch and Pull Comparison

Term Meaning
git fetch Downloads changes
git pull Downloads and integrates
origin/main Remote branch reference
HEAD..origin/main Range of missing commits

All lessons in Beginner