The 18-year-old made 10 first-team appearances last season, eight from the bench.
Head coach Robbie Neilson told the club's official website said: "I'm glad we've got Gary tied up again. He's been a big player for us at youth level and he's a great prospect.
"He played a few games for the first team last season and did really well for the Under-20s, and also for Scotland Under-19s where he was a regular. It's good to get another young prospect's future sorted.
"Being out of contract, Gary could've moved elsewhere but he's decided to stay and hopefully we can help him develop."