What would be the benefit for Microsoft in that case? - They are transforming themselves from a platform company based around windows, it a platform company based around Azure. GitHub is a relevant part there.
This doesn't mean they are only doing good™ with GitHub, but destroying it and open source vendors would be counted to their interests.