LinuxCommandLibrary

git-upload-pack

Send Git objects to a requesting client

SYNOPSIS

git-upload-pack [--stateless-rpc] [--advertise-refs] [--strict] [--timeout=<n>] [--max-input-size=<n>] <directory>

PARAMETERS

--stateless-rpc
    Quit after one request/response cycle; enables stateless HTTP/SSH transport

--advertise-refs
    Print refs and exit immediately after advertisement, without processing requests

--strict
    Avoid <directory>/.git if it exists; enforce exact directory path

--timeout=<n>
    Exit with error if no data read/written after <n> seconds of inactivity

--max-input-size=<n>
    Maximum allowed input size in bytes; aborts larger requests

<directory>
    Path to the Git repository directory (required positional argument)

DESCRIPTION

git-upload-pack is a low-level plumbing command in Git that implements the server-side logic for transferring repository objects to clients during fetch or clone operations.

It handles the Git packfile protocol, reading client requests from standard input and generating packfiles containing the requested objects, writing them to standard output. This command is automatically invoked by Git transports like SSH, HTTP, or Git protocol when a remote repository is contacted for uploading packs.

Primarily used in server environments (e.g., Git hosting services), it supports both stateful and stateless RPC modes. In stateless mode, it processes a single request-response cycle and exits, ideal for HTTP smart servers. It also advertises available refs upon connection.

Security-conscious usage is crucial as it exposes repository contents; servers often wrap it in hooks or access controls. Not intended for direct end-user invocation but essential for Git's distributed workflow, enabling efficient delta-compressed object transfer without full repository dumps.

CAVEATS

Not for direct user execution; exposes repo contents—use server-side controls. Fails silently on invalid requests; monitor logs for timeouts/security issues.

PROTOCOL FLOW

Client sends 'want/have' lines; server responds with ACK/NAK then packfile. Supports thin packs for multi-step fetches.

Invoked as: git-upload-pack '/path/to/repo.git'

SERVER INTEGRATION

Wrapped by git-shell(1), post-update hook, or HTTP CGI. Example SSH: $PATH_GIT/git-upload-pack '$GIT_DIR'.

HISTORY

Introduced in Git 0.99 (2005) as core plumbing for pack protocol; evolved with smart protocols in Git 1.6+ (stateless-rpc, advertise-refs); refined for performance/security in modern versions.

SEE ALSO

Copied to clipboard