Skip to main content
⚡ OpenDevDocs
Git
gitgitGuideBeginner

git fetch — Downloading Remote Updates Safely

How git fetch works: downloading commits and refs without modifying your local working tree, fetch vs pull, and pruning deleted branches (--prune).

Verified: 2026-09-30
Platforms:
all
#git#fetch#remotes#prune

git fetch — Downloading Remote Updates Safely

git fetch downloads commits, files, and refs from a remote repository into your local .git database, updating remote-tracking branches (origin/main) without touching or modifying your local working tree files.


1. Why git fetch is 100% Safe

Unlike git pull, git fetch never causes merge conflicts or overwrites uncommitted local code:

[ Remote GitHub Repository ]
          │
          ▼ git fetch
[ Local Remote-Tracking Branches (origin/main) ]
          │ (You inspect changes with 'git log origin/main')
          ▼ git merge origin/main
[ Local Working Tree & Branch (main) ]

2. Common Fetch Commands

# 1. Fetch from default remote (origin):
git fetch origin

# 2. Fetch all remotes and branches:
git fetch --all

# 3. Fetch and clean up local references to deleted remote branches (--prune):
git fetch --prune

3. Inspecting Changes After Fetching

# Compare your local branch against the freshly fetched remote branch:
git log HEAD..origin/main --oneline

# View diff of incoming changes before merging:
git diff main..origin/main

On this page