The teenager broke into the first team at Tynecastle last season, making 10 league and cup appearances mostly as substitute, in a campaign which saw the club relegated from the Scottish Premiership after being docked 15 points for entering administration.
Head coach Robbie Neilson is delighted the 18-year-old striker has decided his immediate future lies with the Jambos.
Neilson told the club website: "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 U20s, and also for Scotland U19s where he was a regular. It's good to get another young prospect's future sorted.
"Being out of contract, Gary could have moved elsewhere but he's decided to stay and hopefully we can help him develop."