The idea of "sharing merit" or "transferring merit" is very popular in Theravāda Buddhism. I do not believe that it has a basis in the Suttas. I have read that this concept was introduced much later because of folk beliefs.
The closest thing in the Suttas to sharing or transferring of merit is in Pv 1.5 / Khp 7, which talks about food / drink and ghosts:
Outside the walls they stand and at crossroads. At door posts they stand, returning to their old homes.
But when a meal with plentiful food & drink is served, no one remembers them: Such is the kamma of living beings.
Thus those who feel sympathy for their dead relatives give timely donations of proper food & drink — exquisite, clean — [thinking:] "May this be for our relatives. May our relatives be happy!"
And those who have gathered there, the assembled ghosts of the relatives, with appreciation give their blessing for the plentiful food & drink: "May our relatives live long because of whom we have gained [this gift]. We have been honored, and the donors are not without reward!"
For there [in the ghost realm] there's no farming, no herding of cattle, no commerce, no trading with money. They live on what is given here, hungry ghosts whose time here is done.
As water raining on a hill flows down to the valley, even so does what is given here benefit the dead. As rivers full of water fill the ocean full, even so does what is given here benefit the dead.
"He gave to me, she acted on my behalf, they were my relatives, companions, friends": Offerings should be given for the dead when one reflects thus on things done in the past. For no weeping, no sorrowing no other lamentation benefits the dead whose relatives persist in that way.
But when this offering is given, well-placed in the Sangha, it works for their long-term benefit and they profit immediately.
In this way the proper duty to relatives has been shown, great honor has been done to the dead, and monks have been given strength: The merit you've acquired isn't small.
Here is how I understand this Sutta... Dead relatives hang around things to which they were attached during their lives (places and relatives), but nobody cares. When you see good food and drink, you should think "May my deceased relatives be happy". When this is done, your deceased relatives will rejoice because they have been honoured. Ghosts lead a difficult life and offering the thought "May my deceased relatives be happy" helps and sustains the ghosts. Crying and lamentation does not help the deceased relatives, but offering the thought "May my deceased relatives be happy" helps and sustains the ghosts. If the food and drink is offered to the Sangha, the there is even more merit because the monks gain strength as well.
There is another popular chant sometimes called "Sharing Merit with Devas" (not sure where this originated... can't find it in the Tipiṭaka or commentaries):
Ākāsaṭṭhā ca bhummaṭṭhā
devā nāgā mahiddhikā
Puññaṃ taṃ anumoditvā
ciraṃ rakkhantu sāsanaṃ.
Ākāsaṭṭhā ca bhummaṭṭhā
devā nāgā mahiddhikā
Puññaṃ taṃ anumoditvā
ciraṃ rakkhantu desanaṃ.
Ākāsaṭṭhā ca bhummaṭṭhā
devā nāgā mahiddhikā
Puññaṃ taṃ anumoditvā
ciraṃ rakkhantu maṃ paran"ti.
The key word here is "anumoditvā", which is sometimes incorrectly translated as "sharing"; what it really means is "to rejoice" / "to be thankful" / "to appreciate". In other words, we are inviting the Devā to rejoice in what merit we have done... we are not transferring anything to them. Anyway, Devā have lots of merits of their own, so why would they need ours? :-)