Let's ignore whether GPL or whatever license allows GitHub to do this - let the lawyers sort this out. Instead we should focus on whether it is possible to legally prevent such behavior via license.
In other words, where is my GPLv4 with anti-ml clause?
To the extent that training a model is fair use, it will always trump your license.
Fair use essentially means you can use the work without a license. As long as its ‘fair’. The license might literally say ‘no fair use’, but if you’re not abiding by the terms of the license it means nothing.
You can put anything in a license you want, but it doesn’t mean it will stand up in a court of law.
However, as a dev I can think about it and say "to me, this is immoral and unethical", and refuse to use Copilot, not work for any company that uses Copilot, not use GitHub/Microsoft products, pull code from GitHub (if I had any), and decide not to open source stuff in future. Ethics has always been underemphasised in software compared to other engineering disciplines.
Generally, non-technical people are (more) impacted by ML, but in this case it's us as developers and our open source communities. So I hope devs will give it some thought this time. And if this leads to devs thinking about ML more carefully in general, great. Things don't have to be illegal to be unethical.
Is it ethical to do this, when some licenses are clearly chosen because of e.g. attribution or sharing improvements? Did Microsoft/GitHub consider the ethical implications, for example a chilling effect on code being open sourced in future (i.e. people choosing not to open source stuff so it doesn't get gobbled up by Copilot et al.)?