Skip to content

/compare/git/git-fetch-vs-git-pull

git fetch vs git pull: what is the difference?

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated
tool
Git
compares
git fetch vs git pull

git fetch downloads new commits, branches and tags from a remote and updates the remote-tracking branches (origin/main), but does not touch your local branches or your files. git pull runs git fetch and then integrates the fetched branch into your current branch, by merge (the default) or by rebase (git pull --rebase or pull.rebase=true). Fetch is always safe to run; pull changes your branch and can stop with conflicts.

See the difference

Alice pushes a commit to a shared bare repository; Bob fetches, inspects, then integrates:

bash
git init -q --bare -b main origin.git
git clone -q origin.git alice 2>/dev/null
cd alice
printf 'v1\n' > app.txt && git add app.txt && git commit -q -m "v1" && git push -q origin main
cd .. && git clone -q origin.git bob
cd alice
printf 'v2\n' > app.txt && git commit -q -am "v2" && git push -q origin main
cd ../bob
git fetch -q
echo "--- after fetch"
git status -sb | head -1
echo "app.txt: $(cat app.txt)"
git log --oneline main..origin/main
git pull -q --ff-only
echo "--- after pull --ff-only"
git status -sb | head -1
echo "app.txt: $(cat app.txt)"

Output

--- after fetch
## main...origin/main [behind 1]
app.txt: v1
87d8fc1 v2
--- after pull --ff-only
## main...origin/main
app.txt: v2

After fetch, Bob's branch is reported as [behind 1] and his file still says v1; the new commit exists only in origin/main. pull moves main forward and updates the file.

Side by side

git fetchgit pull
Downloads objects and updates origin/*YesYes (runs git fetch first)
Changes your current branchNoYes: merge, rebase or fast-forward
Changes files in the working treeNoYes
Can produce conflictsNoYes
Typical useSee what changed before integrating; update all remotesBring your branch up to date in one step

A safer pull routine

bash
git fetch
git log --oneline HEAD..origin/main      # what is new upstream
git diff HEAD...origin/main              # what it changes
git merge --ff-only origin/main          # or: git rebase origin/main

Sources