The resulting song, inspired by what makes Christmas special for Greggs fans, will be recorded by indie band Silvers and released on iTunes on 19 December.
The baker hopes the crowdsourced charity single will take the top spot in the charts at Christmas. The song will be up against artists including the X Factor winner.
All profits will go to the charity Help for Heroes.
It is the first time Greggs has launched an interactive social media campaign that relies on the engagement of fans.
The concept was developed by digital agency Steel, which has created a character named Festive Jake the Festive Bake after Greggs seasonal Christmas pie, to front the campaign.
Ken McMeikan, Greggs chief executive, says the aim is to raise funds for the charity while doing something fun because consumers are having a tough year and Christmas can be a difficult time for families of the armed forces.