Elon Musk must attend a court hearing in Philadelphia to address a bid by the city's prosecutor to stop his $US1 million prize giveaway, a judge ruled.