Interview Prep/Git & GitHub/GitHub features, history rewriting and scale

How does Git wire protocol v2 improve fetch performance?

AdvancedConceptGitHub features, history rewriting and scale
Answer

Protocol v2 (default since Git 2.26) replaces the huge ref advertisement with a ls-refs command that accepts prefixes, so the client only lists refs it cares about. On repos with hundreds of thousands of refs this cuts the initial handshake dramatically. It is also the base for fetch filters and the object-format capability.

GIT_TRACE_PACKET=1 git ls-remote origin refs/heads/main 2>&1 | head
git -c protocol.version=2 fetch origin
All Git & GitHub questions Roadmap: Git & GitHub

More on GitHub features, history rewriting and scale