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 --tagsOptions
| Flag | What it does |
|---|---|
| --all | Fetch from all remotes |
| --prune / -p | Delete remote-tracking refs that no longer exist |
| --unshallow | Fetch full history into a shallow clone |
| --depth=N | Limit (or deepen) to N commits |
| --tags | Fetch 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
git pull: Usage, Options & Common CI Errorsgit pull fetches from a remote and integrates the changes. Reference for --rebase, --ff-only, and the merge-c…
git clone: Usage, Options & Common CI Errorsgit clone copies a remote repository into a new local directory. Reference for depth, branch, and submodule f…
git remote: Usage, Options & Common CI Errorsgit remote manages the named connections to remote repositories. Reference for add, set-url, -v, remove, and…
git ls-remote: Usage, Options & Common CI Errorsgit ls-remote lists refs on a remote without cloning. Reference for --heads, --tags, --exit-code, and the aut…