LinuxCommandLibrary

git-upload-archive

Send Git archive over a dumb transport

SYNOPSIS

git upload-archive [--stat-only] [--remote=<name>] <tree-ish> [<pathspec>...]

PARAMETERS

--stat-only
    Send only file stats (mode, mtime*20, size) per line instead of full archive contents.

--remote=<name>
    Connect to <name> repository on the remote host instead of current repo.

DESCRIPTION

git-upload-archive is a plumbing command invoked by git-http-backend to handle upload-archive requests in Git's smart HTTP transport protocol. It generates and streams an archive (default: gzip-compressed tar) of the specified <tree-ish> object, optionally filtered by <pathspec>s, directly to stdout for the HTTP client.

When a client performs git archive --remote or equivalent HTTP request, the server executes this command. It first reads a structured request from stdin in Git's pkt-line format: a "want" line with the tree SHA-1, capabilities, and flush packet. The command then invokes git-archive internally with appropriate arguments to produce the archive.

Primarily used in Git hosting setups like cgit or GitLab to enable efficient archive downloads without full clone. Not designed for direct shell use without emulating the exact stdin protocol.

CAVEATS

Plumbing command; requires precise stdin pkt-line input (want <sha1> + capabilities + flush). Direct invocation without HTTP backend context will fail. Outputs to stdout only; no file option. Limited to formats supported by git-archive (tar, zip, etc., default tar.gz).

STDIN REQUEST FORMAT

Expects pkt-line protocol:
want <32-hex tree SHA-1>SP<capabilities>
0000 (flush)

EXIT STATUS

0 on success; non-zero if archive generation or protocol fails.

HISTORY

Introduced in Git 1.6.6 (October 2009) as part of smart HTTP transport enhancements, enabling git archive --remote over HTTP without dumb protocol limitations. Evolved with pkt-line protocol updates in later versions.

SEE ALSO

Copied to clipboard