Anas (May Allah be pleased with him) reported:
When Messenger of Allah (ﷺ) went to Mina, he came to Jamrat-ul-'Aqabah and threw pebbles at it. After that, he went to his lodge in Mina and sacrificed. Then he called for a barber and pointed his right side to him, said, "Shave from here." Then he pointed his left side and said, "Take (hair) from here." Then he distributed his hair among the people.[Al-Bukhari and Muslim].Another narration is: After the Messenger of Allah (ﷺ) had thrown pebbles at Jamrah and sacrificed an animal, he turned the right side of his head towards the barber who shaved it for him. Then he called Abu Talhah Ansari (May Allah be pleased with him) and gave his hair to him. Then he turned his head to the left side and asked the barber to shave it. He gave the hair to Abu Talhah and told him, "Distribute it among the people."
App reference: Book 2, Hadith 47
Arabic/English book reference: Book 2, Hadith 727