IIRC if:
1. company A doesn't file a trademark; and later
2. company B does
Then company B needs to fight the trademark of company A.
Or they wait for company B to strike and defend themselves based on prior art. But that won't do you much good once Github / Amazon took down your stuff, and they won't act unless you show them your trademark or proof that the other trademark rejected. Or you have to take Microsoft / Amazon to court yourself.
So it's better to get the trademark preemptively.
I'm not sure if you then also need to enforce it consistently against others, if you only got the trademark for defensive purposes like the scenario above.