git fetch downloads new commits from the remote and updates remote-tracking branches like origin/main, but leaves your own branch and files untouched. git pull runs git fetch and then immediately integrates the result into your current branch with a fast-forward, merge or rebase, so it can change your files and create commits.
git fetch # look, don't touch
git log --oneline HEAD..origin/main # what's new on the remote
git pull # fetch + integrate into your branch
The difference in one table
git fetch | git pull | |
|---|---|---|
| Downloads new commits | Yes | Yes (it runs fetch first) |
Updates origin/main and other remote-tracking branches | Yes | Yes |
| Changes your current branch | No | Yes |
| Changes files in your working directory | No | Yes |
| Can create a merge commit or rewrite your commits | No | Yes (merge or rebase) |
| Can cause conflicts | No | Yes |
| Safe with uncommitted changes | Yes | Refuses if they would be overwritten |
What git fetch actually does
Your repository keeps two kinds of branches. Local branches such as main are yours; they move only when you commit, merge, rebase or reset. Remote-tracking branches such as origin/main are your repository's record of where the branches on the remote were the last time you talked to it.
The git-fetch documentation describes the command as downloading refs "along with the objects necessary to complete their histories", after which "remote-tracking branches are updated". That is all it does by default. Your main stays exactly where it was, so you can inspect what arrived before deciding what to do with it.
Here is a real session in a test repository. Another developer pushed a commit called Add d, while we committed Add e locally. Then we fetched (remote URL anonymised):
$ git fetch
From github.com:alex/project
e08b4bd..39a4146 main -> origin/main
$ git status
On branch main
Your branch and 'origin/main' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" if you want to integrate the remote branch with yours)
The line e08b4bd..39a4146 main -> origin/main says the remote's main moved and our origin/main was updated to match. Nothing else changed. Before fetching, git status could not have known about Add d: it compares your branch with origin/main as of the last fetch, not with the live remote.
See what a fetch brought in
After a fetch, these commands answer "what would a pull do?":
git log --oneline HEAD..origin/main # commits on the remote you don't have
git log --oneline origin/main..HEAD # your commits the remote doesn't have
git diff --stat HEAD...origin/main # files changed on the remote since you diverged
Output from the same test repository:
$ git log --oneline HEAD..origin/main
39a4146 Add d
$ git diff --stat HEAD...origin/main
d | 1 +
1 file changed, 1 insertion(+)
The two-dot form A..B in git log means "commits reachable from B but not from A". The three-dot form in git diff compares B with the point where the two branches split, so it shows only the remote's changes, not yours reversed.
Once you've looked, you can integrate with git merge origin/main or git rebase origin/main. That two-step sequence is what git pull does in one go.
What git pull actually does
The git-pull documentation spells it out: "First, git pull runs git fetch with the same arguments (excluding merge options) to fetch remote branch(es)... Then it integrates that branch into the current branch." The integration step is one of:
- Fast-forward, when you have no local commits the remote lacks. Your branch pointer simply moves forward. No new commit, no conflicts possible.
- Merge (
git pull --no-rebase), which creates a merge commit joining your commits and the remote's. - Rebase (
git pull --rebase), which replays your local commits on top of the remote's, giving a straight line of history. Git merge vs rebase compares the two in detail.
"You have divergent branches and need to specify how to reconcile them"
When both sides have new commits and you haven't told Git whether to merge or rebase, a pull stops. Here is the exact message from Git 2.45:
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
The current manual (Git 2.55) describes the same behaviour from the other direction: --ff-only "is the default when no method for reconciling divergent histories is provided". Either way, nothing was changed; the fetch part succeeded and only the integration was refused. Pick one:
| Setting | What pull does when histories diverge | Good for |
|---|---|---|
git config --global pull.rebase false | Merges, creating a merge commit | Teams that want history exactly as it happened |
git config --global pull.rebase true | Rebases your local commits on top | Linear history on feature work that isn't shared yet |
git config --global pull.ff only | Refuses; you decide each time | People who want pull to never surprise them |
If you have uncommitted changes to a file the pull needs to update, Git refuses before touching anything:
error: Your local changes to the following files would be overwritten by merge:
d
Please commit your changes or stash them before you merge.
Commit or git stash the changes, then pull again.
One Windows-specific detail: if you never saw this message on Windows, check where your setting comes from. On the Windows 11 machine used to test this article, Git for Windows had pull.rebase=false in its system-wide config file, so pulls merged silently:
$ git config --show-origin --get pull.rebase
file:C:/Program Files/Git/etc/gitconfig false
A --global setting in your user config overrides the system one.
When to use fetch, and when pull is fine
Use git pull when you're on a branch with no local commits, or you know exactly what's coming and how you want it integrated. For a typical "start of the day, get the latest main" it's the right tool.
Use git fetch when:
- You have local commits or uncommitted work and want to see what's coming before anything touches it.
- You want to review a teammate's branch without merging it:
git fetch, thengit switch feature-x(Git creates a local branch trackingorigin/feature-x) orgit log origin/feature-x. - You're about to
git push --force-with-lease. The lease compares against your remote-tracking branch, so it's only as current as your last fetch. The git-push docs also warn that a lease without an explicit expected value "interacts very badly with anything that implicitly runsgit fetchon the remote to be pushed to in the background", such as an editor that auto-fetches. - You want to update all remotes at once (
git fetch --all) or clean up remote-tracking branches deleted on the server (git fetch --prune).
If a pull went wrong
If a merge-style pull stopped with conflicts and you'd rather not deal with them now, git merge --abort puts the branch back. For a rebase-style pull, git rebase --abort does the same. If a merge or fast-forward pull completed but you didn't want the result, git reflog shows where your branch was before, and git reset --hard HEAD@{1} moves it back (this discards uncommitted changes, so commit or stash them first). If Git reports that you're not on any branch after a rebase stopped halfway, see Git detached HEAD.
Frequently asked questions
- Is git pull the same as git fetch plus git merge?
- Essentially yes. The git-pull documentation says pull first runs git fetch with the same arguments, then integrates the fetched branch into the current one. Depending on your settings and flags, the integration step is a fast-forward, a merge or a rebase.
- Can git fetch overwrite my local changes?
- Not with the default settings. A plain git fetch updates remote-tracking branches such as origin/main and leaves your local branches, working files and staged changes alone. It is safe to run at any time, even with uncommitted work.
- How do I see what git fetch downloaded?
- Run git log --oneline HEAD..origin/main to list commits on the remote that you don't have, and git diff HEAD...origin/main to see the changes they introduce. git status also reports how many commits you are ahead of or behind the remote branch.
- What does git fetch --prune do?
- It deletes remote-tracking branches whose branch no longer exists on the remote, for example origin/feature-x after someone deleted feature-x on GitHub. It never deletes your own local branches.