Fetch and Pull
git fetch downloads remote changes; git pull downloads and merges them.
Syntax
git fetch
git pullTo bring changes from GitHub down to your machine you have two options:
git fetch— downloads new commits but does not change your working files. It updates theorigin/*pointers so you can inspect what changed first.git pull— does afetchand then merges the changes into your current branch. It isfetch+mergein one step.
Use fetch when you want to look before you leap; use pull when you are ready to integrate.
Example
# Download without changing your files
git fetch origin
git log origin/main --oneline # inspect what arrived
# Download AND merge into the current branch
git pull
# Pull using rebase instead of a merge commit
git pull --rebaseWhen to use it
- A developer runs git pull at the start of each day to get the latest changes teammates merged overnight.
- A developer uses git fetch before a rebase to inspect what changed on the remote before integrating it.
- A team member fetches to update their remote-tracking branches and then cherry-picks a specific commit without merging everything.
More examples
Fetch without merging
Downloads remote changes into remote-tracking branches without touching your working directory or current branch.
git fetch origin
# Inspect what arrived
git log HEAD..origin/main --oneline
# e4a1f3c Add payment provider integration
# 7b22c9f Bump dependency versionsPull with fast-forward only
Fetches and merges only if a fast-forward is possible, refusing to create a merge commit and keeping history linear.
git pull --ff-only origin mainPull and rebase instead of merge
Rebases your local commits on top of the fetched remote commits instead of creating a merge commit, producing a cleaner linear history.
git pull --rebase origin main
# Replaying local commits on top of fetched changes
# Successfully rebased and updated refs/heads/feature/api
Discussion