Skip to content

git fetch

Description:
Download objects and refs from another repository without merging. Updates your remote-tracking branches.

Syntax:

bash
git fetch
git fetch <remote>
git fetch <remote> <branch>
git fetch --all
git fetch --prune

Examples:

bash
# Fetch from default remote (origin)
git fetch

# Fetch from specific remote
git fetch upstream

# Fetch specific branch
git fetch origin main

# Fetch from all remotes
git fetch --all

# Fetch and remove deleted branches
git fetch --prune

Detailed Explanation:

  • Safe operation - Doesn't modify your working directory or current branch
  • Updates remote branches - Like origin/main, upstream/develop
  • Review before merge - You can inspect changes before integrating
  • Bandwidth efficient - Only downloads new commits

Comparison with git pull:

git fetchgit pull
Downloads onlyDownloads + Merges
Safe, non-destructiveModifies working directory
Review firstAutomatic merge
Use when: checking updatesUse when: ready to integrate

Common Errors:

  • fatal: couldn't find remote refSolution: Branch doesn't exist on remote
  • Permission deniedSolution: Check authentication (SSH keys or credentials)

Pro Tips:

  • Use git fetch origin main:main to update local main without checking it out
  • Run git fetch regularly to stay updated with remote changes
  • Combine with git log origin/main..HEAD to see commits you haven't pushed
  • Use git fetch --dry-run to see what would be fetched

Related Commands:


Released under the MIT License.