The basic mechanism of protecting yourself against a DDoS attack is to identify a pattern in the attack traffic, then block all matching traffic at the edge of your network using extremely high performance hardware.
In order to be effective, DDoS attackers use “amplification”, which is a way to multiply their effective bandwidth. For example, if there is a misconfigured service that you can send 1 KB to trick into sending 1 MB of requests to the victim, you can turn 1 Mbps of bandwidth into 1 Gbps of DDoS, a factor of 1000. The recent attack against GitHub had amplification over 10,000.
However, these amplification tricks cause patterns in the data arriving at the victim, so that it looks nothing like normal traffic. By recognizing and dropping that traffic and only that traffic, a site can stay online for real users despite the attempted DDoS. Most big sites have systems that attempt to do this automatically and humans to step in when those systems fail. In particular, much of the internet is protected by CloudFlare, the largest provider of anti-DDoS services.