Both git fetch and git pull contact a remote repository to retrieve changes. The important difference is what happens afterward: fetch updates your remote-tracking references without changing your current branch, while pull also integrates the fetched changes into the branch you have checked out.
git fetchgives you a chance to inspect incoming commits and changes before integrating them.git pullfetches and then integrates, usually by fast-forwarding or merging; configuration can make it rebase instead.
Understand local and remote-tracking branches
Your local branch, such as main, is the branch you work on. A remote-tracking branch, such as origin/main, is your local record of the remote branch's latest known state. Fetching updates that record; it does not automatically move your local main branch.
Suppose both your local branches point to commit C, then a teammate pushes commit D. Before you fetch, your remote-tracking branch is still at C:
Remote server main: A --- B --- C --- D
origin/main: A --- B --- C
main: A --- B --- C
After git fetch origin, your view of origin/main advances to D, while main remains at C. After integrating the change, your local branch can advance too.
What does git fetch do?
Fetch downloads commits and other Git objects from a remote and updates the remote-tracking references. It leaves your checked-out branch, index, and working-tree files alone:
git status
git fetch origin
git status
git branch -r
Inspect commits on the remote that are not reachable from your current branch:
git log --oneline HEAD..origin/main
Compare the current branch with the fetched remote branch before integrating:
git diff main..origin/main
Once you have reviewed the changes, integrate them explicitly. For example, merge the fetched branch into main after switching to it:
git switch main
git merge origin/main
What does git pull do?
Pull fetches from the configured remote and then integrates the result into the current branch. In the common default setup, that integration is a fast-forward or merge. Git can also be configured to rebase, so a pull is not always exactly “fetch plus merge.”
git pull origin main
This fetches the remote's main branch and integrates it into whichever branch is currently checked out. Check git status and your current branch first so you know where the changes will go.
When you want pull to rebase your local commits on top of the fetched branch, request it explicitly:
git pull --rebase origin main
When you only want a fast-forward update and want Git to stop rather than create a merge commit if the branches have diverged, use:
git pull --ff-only origin main
Fetch and pull compared
- Downloads remote changes: both commands.
- Updates remote-tracking references: both commands.
- Changes the current branch or working tree: fetch does not; pull may, as part of integration.
- Lets you inspect first: fetch does, while pull integrates immediately according to its configured strategy.
- Best fit: fetch for review and control; pull for a quick update when you are ready to integrate.
A review-first workflow with fetch
In a shared project or before updating a critical branch, fetch first so you can see exactly what arrived:
git status
git fetch origin
git log --oneline HEAD..origin/main
git diff main..origin/main
After reviewing the commit list and file changes, choose how to integrate them. Merge when you want to preserve the branch structure, or rebase your unshared local commits when that matches your team's workflow:
git switch main
git merge origin/main
Replace main with the branch you intend to update. The commit and diff commands above compare against origin/main, so use the corresponding remote-tracking branch for your target.
When a pull creates conflicts
If your local and remote branches changed the same lines, a pull that merges may stop with a merge conflict. Git does not silently choose the right content; resolve each conflicted file, review the result, and complete the merge as Git instructs. If you are not ready to handle that integration, use fetch first and inspect the incoming work.
A rebase pull can also produce conflicts while replaying your local commits. Resolve the files and continue or abort the rebase using the commands Git reports. Do not start an integration while unrelated edits are at risk; check git status and commit or safely save your work first.
Common mistakes to avoid
- Expecting
git fetchto update the checked-out branch. It updates remote-tracking references such asorigin/main. - Running
git pullwithout checking which branch is currently checked out. - Assuming pull always merges. Its integration behavior depends on options and Git configuration.
- Comparing a local branch to an outdated remote-tracking reference without fetching first.
- Confusing
main(your local branch) withorigin/main(your last fetched view of the remote branch).
Quick reference
- Download remote changes without integrating:
git fetch origin. - Review incoming commits:
git log --oneline HEAD..origin/main. - Review file differences:
git diff main..origin/main. - Fetch and integrate using the configured pull strategy:
git pull. - Fetch and rebase local commits:
git pull --rebase. - Allow only a fast-forward update:
git pull --ff-only.
Rule of thumb: use git fetch when you want to inspect and choose how to integrate. Use git pull when you are ready to update the current branch using your configured integration strategy.