Terminal GuideTerminal Guide

git fetch Command Guide

Download objects and refs from another repository

5 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git fetchFetch from origin
git fetch <remote>Fetch from specific
git fetch --allFetch all remotes

Options

--pruneRemove stale refs
--tagsFetch all tags
--depth=1Shallow fetch

After Fetch

git log HEAD..origin/mainSee new commits
git merge origin/mainMerge fetched
git rebase origin/mainRebase on fetched

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git fetch command downloads commits, files, and refs from a remote repository into your local repo. Unlike pull, it doesn't merge changes.

bash
# Fetch from default remote (origin)
git fetch

# Fetch from specific remote
git fetch upstream

# Fetch all remotes
git fetch --all

Fetch vs Pull

git fetch

  • • Downloads changes only
  • • Doesn't modify working directory
  • • Safe - lets you review first
  • • You decide when to merge

git pull

  • • Downloads AND merges
  • • Modifies your branch
  • • Quick but less control
  • • Equals: fetch + merge
bash
# These are equivalent:
git pull origin main

# And:
git fetch origin main
git merge origin/main
Tip
Use git fetch when you want to see what changed before integrating. It's the safer choice for reviewing changes.

Common Options

OptionDescription
--allFetch from all remotes
--prune, -pRemove stale remote-tracking refs
--tags, -tFetch all tags
--depth=<n>Limit history depth
--dry-runShow what would be fetched

Reviewing Fetched Changes

bash
# After fetching, see what's new
git fetch origin

# See new commits
git log HEAD..origin/main
git log --oneline HEAD..origin/main

# See the diff
git diff HEAD origin/main

# See changed files
git diff --stat HEAD origin/main

# Then merge when ready
git merge origin/main

# Or rebase instead
git rebase origin/main

Practical Examples

bash
# Daily workflow: fetch, review, merge
git fetch origin
git log --oneline HEAD..origin/main
git merge origin/main

# Fetch and prune deleted branches
git fetch --prune

# Fetch from fork's upstream
git fetch upstream
git merge upstream/main

# Quick check if remote has updates
git fetch --dry-run

# Fetch specific branch
git fetch origin feature-branch

Frequently Asked Questions

What is the difference between fetch and pull?

Fetch downloads changes but doesn't integrate them - your working directory stays unchanged. Pull is fetch + merge in one step. Fetch is safer for reviewing before merging.

Where do fetched changes go?

They go to remote-tracking branches (like origin/main). These are local copies of remote branches. Your local branches are not changed until you merge or rebase.

How do I see what was fetched?

Use "git log HEAD..origin/main" to see commits that are in origin/main but not in your current branch. Or "git diff HEAD origin/main" for changes.

Should I use fetch or pull?

Use fetch when you want to review changes before integrating, or when you might want to rebase instead of merge. Use pull for quick updates when you trust the incoming changes.

Summary

git fetch downloads changes safely without modifying your work. Review what's new, then merge when ready.

Quick Reference

  • git fetch - Fetch from origin
  • git fetch --all - Fetch all remotes
  • git fetch --prune - Remove stale refs
  • git log HEAD..origin/main - See new commits

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles