Topic 3.1
Remotes, Clone, and Fetch vs Pull
In one line
A remote is a named reference to another copy of the repository somewhere else — clone downloads one for the first time, fetch checks for new history without touching your work, and pull is fetch immediately followed by a merge.
Think of it like this
Real-life example: fetch is like checking your mailbox and bringing the mail inside, sorted into a pile — you now HAVE it, but haven't acted on any of it yet. pull is checking the mailbox AND immediately opening and acting on every letter — convenient, but you don't get a chance to look before something happens.
Key ideas
- 01
A REMOTE is simply a named URL pointing to another copy of the repository —
originis the conventional (not mandatory) name for 'the remote I cloned from.'git remote -vlists every remote a repository knows about, with its URL, for both fetching and pushing. - 02
git clone <url>downloads an ENTIRE repository (every commit, every branch) from a remote and sets up a new local copy with that remote automatically configured asorigin— this is how you get started working on an existing project, whether it's a company's private repo or an open-source project on GitHub. - 03
git fetchdownloads any new commits and branches from a remote into your LOCAL copy's remote-tracking branches (likeorigin/main) WITHOUT touching your actual working branches at all — it's purely informational, letting you see what's changed elsewhere before deciding what to do about it. - 04
git pullisgit fetchimmediately followed bygit merge(by default) — it downloads new commits AND immediately merges them into your current branch in one step. This convenience is exactly whypullcan surprise people with an unexpected merge commit or conflict, when a plainfetchfollowed by a deliberate, separate merge would have let them see what was coming first. - 05
git log origin/main(after a fetch) lets you inspect what's new on the remote's main branch WITHOUT merging anything yet — genuinely useful for reviewing incoming changes before committing to bringing them into your own branch, especially on a repository where surprises matter.
Code & diagrams
fetch downloads and stops; pull downloads and immediately merges.
Clone a real public repo to practice safely — no account or write access needed for fetch.
# Clone any public repository (read-only, no account needed)
git clone https://github.com/git/git.git git-source
cd git-source
# See the remote(s) configured automatically by clone
git remote -v
# origin https://github.com/git/git.git (fetch)
# origin https://github.com/git/git.git (push)
# Download new history WITHOUT touching your current branch
git fetch origin
# Inspect what's new on the remote's main branch before merging anything
git log origin/master --oneline -5
# (this repo's default branch happens to be "master")
# Only now, deliberately, bring it into your own branch
git merge origin/master
# or, in one step: git pull origin masterExplain it without notes
What's the practical difference between git fetch and git pull, and why might you deliberately prefer fetch first?
You just ran git clone. What exactly got set up automatically that lets git pull work immediately afterward with no extra configuration?
Practice
Clone any public repository, run git remote -v to see its configured remote, then git fetch followed by git log origin/<default-branch> to inspect its latest history without merging anything.
In that same cloned repo, deliberately run git pull and observe whether it resulted in a fast-forward or an actual merge, based on whether your local branch had diverged at all.
Trade-offs
- ↔
Pull's convenience (one command instead of two) is genuinely nice for a simple, low-stakes personal project where surprises don't matter much — but on a shared, actively-changing repository, many experienced developers deliberately configure
git pullto REBASE instead of merge (git config pull.rebase true), or just use fetch-then-merge-deliberately as a habit, specifically to avoid unexpected merge commits cluttering a history that's meant to stay clean.
Done when you can
I can explain what a remote is and list a repository's configured remotes.
I understand fetch downloads without merging, while pull downloads and merges immediately.
I know how to inspect a remote branch's new commits before merging them into my own.