Progress:
TIER 3 · MODULE 52· Expert

git receive-pack

Lives on the remote. Validates and stores incoming packs.

🎯 What & why

git receive-pack is the server-side process that accepts a push. It lives on the remote, reads update commands and the incoming packfile from stdin, runs the pre-receive/update/post-receive hooks, and atomically moves the refs.

🧠 Mental model

Push is a two-process conversation: git push on the client spawns send-pack, which talks (over ssh, smart HTTP, or git://) to receive-pack on the server. receive-pack is the bouncer, the warehouse, and the ref clerk in one binary.

🛠️ Synopsis

git receive-pack [--http-backend-info-refs] <directory>

Invoked by the transport layer (sshd, `git http-backend`, `git daemon`); users almost never run it directly. `<directory>` is the path to the target repository on the server.

🎚️ Switches & options

FlagWhat it does
<directory>Path to the bare or non-bare repo that is receiving the push.
--http-backend-info-refsEmit the smart-HTTP advertisement format instead of starting a session.
(implicit) stdin protocolReads <old-sha> <new-sha> <ref> update commands followed by a packfile.
(implicit) hooksRuns pre-receive, then per-ref update, then post-receive and post-update.
(implicit) atomic refsWith receive.atomic=true (or --atomic on the client) ref updates land all-or-nothing.

💡 Use cases

🧪 Examples

Server side of an ssh push (auto-invoked)
ssh git@127.0.0.1 git-receive-pack '/srv/git/repo.git'
Smart-HTTP info/refs advertisement
git receive-pack --http-backend-info-refs /srv/git/repo.git
Reject force-pushes via hook
echo 'exec >&2; while read o n r; do [ "$o" = 0000000000000000000000000000000000000000 ] || git merge-base --is-ancestor "$o" "$n" || exit 1; done' > hooks/pre-receive && chmod +x hooks/pre-receive
Enable atomic ref updates
git config receive.atomic true

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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