GitHub stores millions of repositories the same way they exist on our local machine - literally as git repositories. Nothing very special.
Instead of one copy, GitHub stores at least three copies of every single repository to make sure the code is never lost. This replication system is called Spokes at GitHub.
When we push code, the write is not accepted unless a strict majority of replicas - at least 2 out of 3 - can successfully apply the change and produce the same result.
Interestingly, the system watches real application traffic to detect failures. If three requests in a row fail to one of the servers for a repository, that server is marked offline, and traffic is routed to other replicas within seconds. No heartbeats needed - just monitoring the real user operations.
Each replica lives in a different rack. When an entire rack goes down, repositories remain available because the other copies live elsewhere. And when repairs are needed after a server failure, the whole cluster helps out - the bigger the cluster, the faster it recovers.
Spokes refuses write operations that it cannot commit to at least two places. This ensures that when your push succeeds, your code is already safe.
This is also why GitHub rejects pushes during partial outages. Reads might still work, but writes fail because the system refuses to risk losing data.
This is pretty much how GitHub stores repositories and, more importantly, prefers a simple design with consistency over durability and availability.
Hope you also found it interesting.