sync

git fetch

Downloads objects and refs from a remote without modifying your working tree or current branch. Safest way to see what's new upstream before integrating.

git fetch [<remote>] [<refspec>]

Common flags

Flag Purpose
--all Fetch from all configured remotes
--prune Delete local refs for branches removed on the remote
--tags Also fetch all tags
--depth <n> Limit fetched history to n commits
--unshallow Convert a shallow clone into a full one

Examples

git fetch origin

Update remote-tracking branches for origin

git fetch --all --prune

Fetch every remote and clean up deleted branches

git fetch origin main:main

Update local main from origin without checking out

Gotcha

Fetch does NOT update your working branch; you still need merge, rebase, or pull to integrate the new commits.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge