Skip to content
LatchkeyLatchkey home

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.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git fetch: Usage, Options & Common CI Errors?
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 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

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card