Skip to content
Latchkey

git fetch: Usage, Options & Common CI Errors

git fetch updates your remote-tracking branches but never changes your local branch or files.

Fetch is the safe way to see what is new upstream. It is also how you deepen a shallow clone in CI.

What it does

git fetch retrieves commits, files, and refs from a remote into your local object store and updates remote-tracking refs like origin/main. Your checked-out branch and working tree are untouched.

Common usage

Terminal
git fetch origin
git fetch --all --prune
git fetch --unshallow          # convert shallow clone to full
git fetch --depth=50 origin main
git fetch origin --tags

Options

FlagWhat it does
--allFetch from all remotes
--prune / -pDelete remote-tracking refs that no longer exist
--unshallowFetch full history into a shallow clone
--depth=NLimit (or deepen) to N commits
--tagsFetch all tags

Common errors in CI

fatal: refusing to merge unrelated histories or "shallow update not allowed" / tools that need full history failing - the runner did a shallow clone (depth 1). Run git fetch --unshallow, or set fetch-depth: 0 in actions/checkout so tags and full history are present.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →