Fetch or pull? Get GitHub's changes safely
When to use this: GitHub may have newer commits (another PC, a merged PR) and you want them locally.
Before you start
Steps
-
Look first (fetch)
terminalgit fetch git log HEAD..origin/main --onelineFetch downloads but changes nothing in your files. The log shows what a pull would bring in.
-
Take the changes (pull)
terminalgit pullDoes
fetchand then mergesorigin/maininto your current branch. If you have no local commits it simply fast-forwards.Expected output
Updating 3f2a1b9..8c4d7e0 Fast-forward src/pages/index.astro | 4 ++--
-
Strict option: refuse anything but a fast-forward
terminalgit pull --ff-onlyIf your branch has diverged, this stops instead of creating a merge commit. Then you decide whether to merge or rebase deliberately.
How to verify it worked
git status -sbshows nobehind.
How to undo it
If a pull merged something you did not want and you have not pushed, go back to where you were before the pull:
git reset --hard ORIG_HEADCommon errors and fixes
fatal: Need to specify how to reconcile divergent branches Both sides have new commits. Choose: git pull --no-rebase (merge) or git pull --rebase. To make merge the default: git config --global pull.rebase false. Your local changes would be overwritten by merge Commit or stash first (git stash push -u), then pull. Q&A
Is git pull just git fetch plus something?
Yes: fetch followed by merge (or rebase if configured) of the upstream branch into your current branch.
Why would I ever fetch without pulling?
To inspect first. It lets you compare (git log HEAD..origin/main) without touching your files.