Command Palette

Search for a command to run...

Hectal
PHASE 3Intermediate ~14 min· topic 1 of 4

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.

0/4 · 0%

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

  1. 01

    A REMOTE is simply a named URL pointing to another copy of the repository — origin is the conventional (not mandatory) name for 'the remote I cloned from.' git remote -v lists every remote a repository knows about, with its URL, for both fetching and pushing.

  2. 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 as origin — 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.

  3. 03

    git fetch downloads any new commits and branches from a remote into your LOCAL copy's remote-tracking branches (like origin/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.

  4. 04

    git pull is git fetch immediately followed by git merge (by default) — it downloads new commits AND immediately merges them into your current branch in one step. This convenience is exactly why pull can surprise people with an unexpected merge commit or conflict, when a plain fetch followed by a deliberate, separate merge would have let them see what was coming first.

  5. 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

FetchVsPulldiagram

fetch downloads and stops; pull downloads and immediately merges.

Rendering diagram…
remotes-fetch-pull.shmarkdown

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 master

Explain it without notes

01

What's the practical difference between git fetch and git pull, and why might you deliberately prefer fetch first?

02

You just ran git clone. What exactly got set up automatically that lets git pull work immediately afterward with no extra configuration?

Practice

01

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.

02

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 pull to 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.