Just one problem with that: Every piece of work - code or otherwise, made by a human or not - may violate copyright law. There really is no way to know without actually checking against all other works (which you can’t because you don’t have access to all of them).
What GitHub does is what a sane person would do: React to claims. They just assume that what they get uploaded isn’t violating copyright until someone claims otherwise. And as it is literally impossible to actually know, that is the only sane way to approach this problem apart from just not hosting other people’s stuff at all.
Just one problem with that: Every piece of work - code or otherwise, made by a human or not - may violate copyright law. There really is no way to know without actually checking against all other works (which you can’t because you don’t have access to all of them).
What GitHub does is what a sane person would do: React to claims. They just assume that what they get uploaded isn’t violating copyright until someone claims otherwise. And as it is literally impossible to actually know, that is the only sane way to approach this problem apart from just not hosting other people’s stuff at all.