Skip to content

fetch-pack Git Command Guide

The git fetch-pack command is used to receive missing objects from another repository. It invokes git-upload-pack on a remote repository and requests objects needed to update specified heads. Usually git fetch is preferred over this low-level command.

Terminal window
git fetch-pack [--all] [--quiet|-q] [--keep|-k] [--thin] [--include-tag] [--upload-pack=<path>] [--depth=<n>] [--no-progress] [-v] <repository> [<refs>...]
OptionDescription
—allFetch all remote refs
—stdinTake refs from stdin
-q, —quietLess verbose output
-k, —keepCreate packfile instead of unpacking
—thinFetch thin pack with deltified objects
—include-tagDownload annotated tags with referenced objects
—upload-pack=Path to git-upload-pack on remote
—depth=Limit fetch depth
—shallow-since=Deepen shallow repo to commits after date
—shallow-exclude=Exclude commits from specified ref
—no-progressSuppress progress display
—check-self-contained-and-connectedVerify pack integrity
-vVerbose output
—refetchSkip negotiation and fetch all matching objects
ParameterDescription
URL to remote repository
Remote heads/refs to update (default: all)
Terminal window
git fetch-pack --all origin

Fetch all remote refs from origin.

Terminal window
git fetch-pack --depth=1 origin

Fetch with shallow clone depth of 1.

Terminal window
git fetch-pack origin refs/heads/main

Fetch only the main branch from origin.

Terminal window
git fetch-pack --thin --include-tag origin

Fetch thin pack including annotated tags.

Terminal window
git fetch-pack -v origin

Show verbose output during fetch.

Terminal window
git fetch-pack --keep origin refs/heads/develop

Create single packfile without unpacking objects.

To fetch all remote refs, use the —all option:

Terminal window
git fetch-pack --all origin

To create shallow clones with depth limit, use:

Terminal window
git fetch-pack --depth=<n> origin

To include annotated tags, use —include-tag:

Terminal window
git fetch-pack --include-tag origin

To fetch a specific branch, specify the ref:

Terminal window
git fetch-pack origin refs/heads/<branch>

To keep data as packfile instead of unpacking, use —keep:

Terminal window
git fetch-pack --keep origin

To troubleshoot fetch issues, use verbose output:

Terminal window
git fetch-pack -v origin

Applications of the git fetch-pack command

Section titled “Applications of the git fetch-pack command”
  1. Low-level repository synchronization
  2. Implementing custom fetch logic in tools
  3. Network protocol testing and debugging
  4. Creating specialized clone operations
  5. Building mirror and backup systems