Progress:
TIER 3 · MODULE 55· Expert

git upload-pack

The complement to fetch-pack.

🎯 What & why

git upload-pack is the server side of fetch and clone. It listens to a client's fetch-pack, negotiates which objects are wanted vs already had, and streams back a packfile containing exactly the missing objects.

🧠 Mental model

Two processes playing 20-questions across a pipe: client sends want <oid> lines, server replies with have/ACK rounds, then ships a single packfile. Lives behind ssh://, git://, and http:// (via git-http-backend).

🛠️ Synopsis

git upload-pack [--strict] [--timeout=<n>] [--stateless-rpc]
                [--advertise-refs] [--http-backend-info-refs]
                [--no-done] <directory>

# Typical invocation by sshd
git-upload-pack '/srv/git/repo.git'

# Smart-HTTP info/refs phase
git-upload-pack --stateless-rpc --advertise-refs <dir>

🎚️ Switches & options

FlagWhat it does
--strictRequire <directory> to be a real Git dir; don't try .git suffix fallbacks
--timeout=<n>Seconds to wait on the client before giving up; useful behind flaky networks
--stateless-rpcSpeak the smart-HTTP single-shot RPC dialect instead of long-lived SSH/git-protocol
--advertise-refsOnly emit the initial ref advertisement and exit (HTTP info/refs phase)
--http-backend-info-refsAlias of --advertise-refs used by git-http-backend
--no-doneAllow the v0/v1 negotiation to skip the final done round-trip (latency win)

💡 Use cases

🧪 Examples

What sshd runs for git clone git@host:repo.git
git-upload-pack '/srv/git/repo.git'
Manual ref advertisement against a local bare repo on 127.0.0.1
git upload-pack --advertise-refs /srv/git/repo.git
Smart-HTTP info/refs simulation
git upload-pack --stateless-rpc --http-backend-info-refs /srv/git/repo.git
Tighten the negotiation timeout
GIT_PROTOCOL=version=2 git -c uploadpack.timeout=30 upload-pack /srv/git/repo.git

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.