Fetch and Pull

git fetch downloads remote changes; git pull downloads and merges them.

Syntaxgit fetch git pull

To bring changes from GitHub down to your machine you have two options:

  • git fetch — downloads new commits but does not change your working files. It updates the origin/* pointers so you can inspect what changed first.
  • git pull — does a fetch and then merges the changes into your current branch. It is fetch + merge in one step.

Use fetch when you want to look before you leap; use pull when you are ready to integrate.

Example

Example · bash
# Download without changing your files
git fetch origin
git log origin/main --oneline   # inspect what arrived

# Download AND merge into the current branch
git pull

# Pull using rebase instead of a merge commit
git pull --rebase

When to use it

  • A developer runs git pull at the start of each day to get the latest changes teammates merged overnight.
  • A developer uses git fetch before a rebase to inspect what changed on the remote before integrating it.
  • A team member fetches to update their remote-tracking branches and then cherry-picks a specific commit without merging everything.

More examples

Fetch without merging

Downloads remote changes into remote-tracking branches without touching your working directory or current branch.

Example · bash
git fetch origin

# Inspect what arrived
git log HEAD..origin/main --oneline
# e4a1f3c Add payment provider integration
# 7b22c9f Bump dependency versions

Pull with fast-forward only

Fetches and merges only if a fast-forward is possible, refusing to create a merge commit and keeping history linear.

Example · bash
git pull --ff-only origin main

Pull and rebase instead of merge

Rebases your local commits on top of the fetched remote commits instead of creating a merge commit, producing a cleaner linear history.

Example · bash
git pull --rebase origin main
# Replaying local commits on top of fetched changes
# Successfully rebased and updated refs/heads/feature/api

Discussion

  • Be the first to comment on this lesson.
Fetch and Pull — GitHub | SoundsCode