الانتقال إلى المحتوى
DevOps والـ CloudGit· 6 دقائق للقراءة

git pull Doesn't Just Download: It's fetch Plus merge (or rebase)

git fetch is the download. git pull also integrates into your branch, and that second step is where conflicts come from.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

Omar has one commit he hasn't pushed yet, adding VAT to the checkout total. Before stand-up he runs git pull "just to download what the team pushed". The terminal answers with CONFLICT (content): Merge conflict in checkout.js, the file is full of conflict markers, and his branch is in the middle of a merge he never asked for. He wanted to look. Git changed his branch.

The common misconception

The belief: git pull downloads the latest changes from the remote. It's the opposite of git push, the command that gets you "up to date", and it's safe to run any time.

It's a reasonable belief. The names suggest a pair: push uploads, so pull must download. And most of the time you pull with no commits of your own, where it really does look like a download. In our test, a clone with nothing new printed Updating f3f6d28..85d5919 and Fast-forward: the branch simply moved ahead.

That's the half-truth. A pull always starts with a download, but it never stops there. The second half only goes unnoticed while your branch has nothing new of its own.

What actually happens

Your clone keeps bookmarks of the remote

Your repository doesn't read the remote's branches live. It keeps a local copy of where they were, called and named like origin/main. Pro Git describes them as "local references that you can't move; Git moves them for you whenever you do any network communication." Your own main and the bookmark origin/main are two different pointers, and they can point at different commits.

git fetch is the download

git fetch downloads the commits you don't have yet and moves the bookmarks, so origin/main now matches the remote. Your branches stay where they were, and Pro Git says fetch "will not modify your working directory at all." Afterwards you can compare main with origin/main and decide what to do.

git pull adds an integration step

The git pull docs describe two steps: "First, git pull runs git fetch with the same arguments", then it picks the branch to integrate, by default the upstream of your current branch, and "integrates that branch into the current branch." That second step has several modes. A moves your branch ahead when you have no commits of your own. --no-rebase runs git merge, --rebase runs git rebase, and the pull.rebase and pull.ff settings choose for you. When your branch and the remote have diverged and nothing chooses, the docs say pull does "fast-forward" updates only and "fails if your local branch has diverged". In our test, a diverged pull with no settings stopped with fatal: Need to specify how to reconcile divergent branches., after it had already fetched.

Which mode you get depends on configuration

Omar's pull merged because something had chosen for him. On our Windows test machine, git config --show-origin --get-regexp '^pull' printed pull.rebase false, read from C:/Program Files/Git/etc/gitconfig, the system file Git for Windows installs. So a plain git pull there means fetch plus merge. Git's own hint for diverged branches suggests git config pull.rebase false, so it's an easy value to set once and forget. Rebasing on pull is another choice with its own trade-offs; a later article compares merge and rebase.

The fix: download first, then decide

Here are both sessions from Omar's clone, run on Git 2.54:

Bash terminal
git pull   # "just download what the team pushed"# From ../shop#    f3f6d28..85d5919  main       -> origin/main# Auto-merging checkout.js# CONFLICT (content): Merge conflict in checkout.js# Automatic merge failed; fix conflicts and then commit the result.git status --short# UU checkout.js

The first line of each output is identical: both commands downloaded the same commit and moved origin/main. The difference is everything after it. The pull went on to merge, hit a conflict and left checkout.js unmerged (UU). The fetch stopped and showed the situation: one commit on each side, and the incoming one touches checkout.js, the file Omar changed. Running git merge origin/main right after that fetch printed the exact same CONFLICT lines. That merge is all the pull had added, but now Omar would run it on purpose, when his work is ready.

Your situationWhat git pull did on Git 2.54
No local commits, the remote moved aheadFetched, then fast-forwarded your branch
Diverged, no pull setting anywhereFetched, then stopped: Need to specify how to reconcile divergent branches
Diverged, pull.rebase falseFetched, then merged: a merge commit, or conflicts like Omar's
Diverged, pull.ff onlyFetched, then stopped: Not possible to fast-forward, aborting
Uncommitted edits in a file the incoming commit changesFetched, then stopped: your changes "would be overwritten by merge"

How to apply it in your project

  1. Find out what your pull doesRun git config --show-origin --get-regexp '^pull'. It lists every pull setting and the file it comes from, including system files you never edited. No output means Git's default: fast-forward, or stop.
  2. Use git fetch when you want to lookgit fetch, then git status -sb for ahead/behind counts, git log main..origin/main for the incoming commits and git diff --stat main...origin/main for the files they touch. None of it changes your branch.
  3. Integrate on purposeMerge or rebase origin/main when your work is committed and you have time for conflicts. Or set pull.ff only so pull never decides for you.
  4. Commit or stash before integratingWhen uncommitted edits sit in files the incoming commits change, the merge refuses to start, as the table shows. Start from a clean git status.

Key takeaways

  • git pull is git fetch followed by integrating the fetched branch into your current branch.
  • git fetch is the real "download": it moves origin/main and leaves your branches and files alone.
  • Whether pull fast-forwards, merges, rebases or stops depends on settings that can come from files you never edited.
  • When you have local commits, a pull can create a merge commit or leave you mid-merge with conflicts.
  • Fetch to look, integrate on purpose, and consider pull.ff only so pull never decides for you.

📚 المصادر

  1. git-pull — Git reference
  2. git-fetch — Git reference
  3. Git Branching: Remote Branches — Pro Git

التعليقات (0)