Imam ‘Ali (‘a), at the sensitive young age when character and spirituality is more easily shaped and formed, was constantly in the house of the Prophet (ṣ) and under the influence of his training and education.
Imam ‘Ali (‘a), at the sensitive young age when character and spirituality is more easily shaped and formed, was constantly in the house of the Prophet (ṣ) and under the influence of his training and education. Islamic historians have written:
“One year, a great famine overtook Mecca. At that time, Abū Ṭālib, who was the uncle of the Prophet (ṣ), had a very large family and this caused him to have very heavy expenses. The Prophet (ṣ) approached another of his uncles, who was named ‘Abbās (one of the very wealthy individuals of the tribe of Hāshim) and suggested that each of them take one of Abū Ṭālib’s children to their home and care for them as their own, in order that his financial burden be lessened. ‘Abbās agreed to this and they both went to Abū Ṭālib and presented their idea to him. Abū Ṭālib also agreed to their proposal and they each took one of his sons under their care. ‘Abbās took Ja’far and the Prophet (ṣ) took ‘Ali (‘a). ‘Ali (‘a) was at the Prophet’s (ṣ) house until the time when he was commissioned with prophethood.When this took place, ‘Ali (‘a) confirmed his Prophethood (ṣ) and followed him. The Prophet (ṣ), after s e l e c ting ‘Ali (‘a) to bring to his home, declared: “I s e l e c ted the same one whom God had s e l e c ted for me.”
Prophet Muhammad (ṣ), after the passing of ‘Abd al-Muṭṭalib, had lived at the house of his uncle Abū Ṭālib and he had been raised under his guardianship and loving care. By taking one of Abū Ṭālib’s children under his wing, he wished to help compensate for the efforts and hardships that Abū Ṭālib and his wife Fatimah bint Asad had undergone in raising him.
During his time as caliph, Imam ‘Ali (‘a) mentioned his education and training under the Prophet (ṣ) in his sermon of ‘Qāṣi’ah’. He said: “You (companions of the Prophet (ṣ)) are aware of my closeness with the Prophet of God (ṣ) and the special position which I had with him. You know that when I was a young child, he would embrace me in his arms, and would hold me tightly to his chest, and would lay me to sleep on his own bed in such a way that I would feel him close next to me and I would smell his sweet perfume, and he would feed me with his own hands.
In the same way that a child follows his mother, I would follow him wherever he went, and each day he would enlighten me with one of his ethical and moral virtues. After teaching me, he would command me to act upon that which I had learned.” 
 Refer to the sources below: Ibn Athīr, Al-Kāmil fī al-tārīkh, Beirut, Dār Ṣādir, 1399 Hijrī Qamarī, vol. 2, p. 58; Ibn Hishām, ‘Abd al-Malik, Al-Sīrā al-nabūwīyah, researched by Muṣṭafā al-Saqā’, Ibrāhīm al-Abyārī, ‘Abd al-Ḥafīẓ Shalbī, Cairo, Maktabah al-Muṣṭafā al-Bābī al-Ḥalabī (Published by Maktabah al-Ṣadr Tehran), 1355 Hijrī Qamarī, vol. 1, p. 262; Ṭabarī, Muḥammad ibn Jarīr, Tārīkh al-umam wa al-mulūk, Beirut, Dār al-Qāmūs al-Ḥadīth, (Bī Tā), vol. 1, p. 213; Ibn Abī al-Ḥadīd, Commentary on the Nahj al-Balāghah, Researched by Muḥammad Abū al-Faḍl Ibrāhīm, al-Ṭab’at al-’Ūlā, Cairo, Dār Aḥyā’ al-Kutub al-’Arabīya, 1378 Hijrī Qamarī, vol. 13, p. 119.  Abū al-Faraj Iṣfahānī, Maqātil al-ṭālibīn, Najaf Ashraf, Manshūrāt al-Maktabah al-Ḥaīdārīa, (Bī Tā), p. 15.  Nahj al-Balāghah, Ṣubḥī Ṣālih, Sermon 192. و قد علمتم موضعي من رسول الله بالقرابة القريبة والمنؤلة الخصيصة وضعني في حجره و انا ولد يَضُمّني إلي صدره، و يكْنُوُفي في فراشه، و يُمِسّني جسده، يُشِمُّني عرفه، و كان يمضغ الشئ ثم يُلقمُنيه... و لقد كنت اتبعه اتباع الفصيل أثراممّه يرفع في كل يوم من اخلاقه علما يأمرني بالإقتداءبه.  Taken from the text: Sīrah Pīshvayān, Mahdī Pīshvāī, Mu’asasah Imam Ṣadiq (‘a), Qum, 1390 Hijrī Shamsī, 23rd Edition, p. 26.