CodeBlanks Logo Icon CodeBlanks

fetch vs pull

Learn that fetch does not merge while pull does.

The Difference Between Fetch and Pull

git fetch downloads changes from the remote repository but does not merge them into the current working branch. git pull downloads remote changes and integrates them into the current branch.

git fetch origin
git pull origin main

Use fetch to inspect changes first, or pull to download and integrate them together.

The Integration Step of Pull

The git pull operation generally includes retrieving data from the remote repository and integrating those changes into the current branch. This integration usually happens through a merge operation.

git pull origin main

If the remote and local histories are incompatible, a merge conflict may occur during pull. In that case, you need to resolve the conflict.

Practice Get Remote Changes with Pull

Download changes from the main branch of the origin remote and integrate them into the current branch. Then check the repository status.

Starter code

terminal
# Uzak değişiklikleri indir ve entegre et

# Durumu kontrol et

Sample solution

terminal
git pull origin main
git status

Expected output

On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean

Questions and answers

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

1 Which command downloads remote changes and integrates them into the current branch?

  • git status
  • git fetch
  • git remote
  • git pull Correct answer

Explanation: <code>git pull</code> downloads remote changes and integrates them into the current branch. Fetch only downloads remote information.

2 Integrate a Specific Remote Branch

Question
git pull origin ____
Answer
git pull origin feature

Explanation: The command specifies the remote name first, followed by the branch to integrate. The remote is specified as origin here.

3 Fetch and Pull Comparison

Term Meaning
git fetch Downloads, does not merge
git pull Downloads and integrates
merge Combines branches
origin Remote repository label

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow