Git Pull Explained — Difference Between Git Fetch and Git Pull

In the previous blog, we looked at the Git fetch command.
Now let’s understand Git pull, one of the most used Git commands in daily development.

We’ll cover:

  • What Git fetch does (quick recap)
  • How Git pull works internally
  • Difference between fetch and pull
  • Using pull with merge vs rebase
  • Common mistakes and gotchas

Quick Recap: Git Fetch

The git fetch command:

  • Downloads all new commits and updates from the remote repository
  • Updates the remote tracking branches (origin/main, origin/test, etc.)
  • Does not change your local branches automatically

👉 After fetch, you must manually run git merge or git rebase to bring those changes into your current branch.


Git Pull = Fetch + Merge

The git pull command is basically:

git pull = git fetch + git merge
  • First, it fetches the updates from the remote.
  • Then, it merges those updates into your current local branch automatically.

Example:

git pull origin main

👉 This:

  • Fetches changes from origin/main
  • Merges them into your local main branch

Example Walkthrough

Imagine this setup:

  • Local branches: main, test
  • Remote branches: origin/main, origin/test
  • Initially, both local and remote are pointing to the same commit.

Now you add new commits directly on GitHub (one on main, one on test).

Step 1: Pull on main

git switch main
git pull origin main

👉 Local main is updated with the new commits from origin/main. 👉 Fast-forward merge happens if no conflicts exist.

✅ But notice: The test branch is not updated.


Pull Only Updates One Branch

This is an important difference:

  • git fetch updates all remote tracking branches.
  • git pull only updates the branch you request, and merges it into your current branch.

If you want updates for the test branch:

git switch test
git pull origin test

Now the local test branch gets updated.


Git Pull with Rebase

By default, pull uses merge. But if you prefer a clean linear history, you can pull with rebase:

git pull --rebase origin main

👉 This applies your local commits on top of the fetched commits instead of merging.


What If You Pull the Wrong Branch?

Suppose you’re on main but run:

git pull origin test

👉 Git will fetch commits from origin/test and merge them into local main. This might create unwanted history!

⚠️ Always double-check which branch you’re on before pulling.


Summary

  • git fetch downloads data from remote but does not touch local branches.
  • git pull = git fetch + git merge (updates your local branch directly).
  • Use --rebase if you prefer rebase over merge.
  • Pull only updates one branch at a time, not all.
  • Be careful not to pull the wrong branch into your current branch.

Keep Learning 🚀

👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.

👉 My YouTube Channel – More videos, more fun, and lots of learning!

👉 📺 Watch this topic in video form

Stay curious, keep coding, and let’s make learning fun together! 🎉