The Messenger of Allah ﷺ said, "Actions are judged only by intentions, and every person will have only what they intended. So whoever migrated for the sake of Allah and His Messenger, his migration is for Allah and His Messenger. And whoever migrated for some worldly gain he sought, or a woman he wished to marry, his migration is for whatever he migrated toward."
أن رسول الله ﷺ قال: إنما الأعمال بالنيات، وإنما لكل امرئ ما نوى، فمن كانت هجرته إلى الله ورسوله فهجرته إلى الله ورسوله، ومن كانت هجرته إلى دنيا يصيبها، أو إلى امرأة ينكحها، فهجرته إلى ما هاجر إليه.
Bukhari narrated it in the Book of How the Revelation Began (1), from Humaydi Abdullah bin Zubayr, who said, Sufyan told us, who said, Yahya bin Saeed Ansari told us, who said, Muhammad bin Ibrahim Taymi informed me, that he heard Alqama bin Waqqas Laythi say, I heard Umar bin Khattab, on the pulpit, say, I heard the Messenger of Allah ﷺ say, then he related the hadith.Bukhari also narrated it in the Book of Faith (54), and Muslim in Jihad and Expeditions (1907), both of them from Abdullah bin Maslama bin Qanab, who said, Malik told us, from Yahya bin Saeed, with his chain, and their wording is the same, except that in Muslim it reads, "Actions are only by intention, and a person only gets what he intended."This hadith is not found in the narration of Yahya bin Yahya Laythi in his Muwatta, nor did Jawhari Ghafiqi mention it in Musnad Muwatta, even though he compiled in it the narration of Abdullah bin Maslama Qanabi. So either the hadith fell out of it, or the printed copy has an omission. It is found only in the narration of Muhammad bin Hasan Shaybani (982) from Malik, a narration that Ghafiqi missed, so his book did not include it.Tirmidhi said, Abdul-Rahman bin Mahdi said, "This hadith ought to be placed in every chapter." Jami Tirmidhi (1647).Know then, may Allah have mercy on you, that this hadith is one that Yahya bin Saeed Ansari alone transmitted, from Muhammad bin Ibrahim Taymi, from Alqama bin Abu Waqqas Laythi, from Umar bin Khattab . The hadith then became widely established through Ansari, transmitted from him by a great multitude and an enormous number of people. It has been said that more than two hundred narrators transmitted it from him, and it has also been said that seven hundred narrators transmitted it from him.Its meaning has also been narrated from a group of companions, among them Abu Saeed Khudri, Anas bin Malik, Ali bin Abu Talib, Abu Hurairah, Hazzal bin Yazid Aslami, and others, but all of these narrations are defective, and none of them is sound except the hadith of Umar bin Khattab
.