Umar bin Khattab reported,

The Prophet ﷺ said, "Actions are judged by intention, and a person receives only what they intended. Whoever's migration was for Allah and His Messenger, their migration is to Allah and His Messenger. And whoever's migration was for some worldly gain to be acquired or a woman to be married, their migration is to whatever they migrated for."

Bukhari 2529

Sahih

حدثنا محمد بن كثير عن سفيان حدثنا يحيى بن سعيد عن محمد بن إبراهيم التيمي عن علقمة بن وقاص الليثي قال سمعت

عمر بن الخطاب رضي الله عنه

عن النبي ﷺ قال الأعمال بالنية ولامرئ ما نوى فمن كانت هجرته إلى الله ورسوله فهجرته إلى الله ورسوله ومن كانت هجرته لدنيا يصيبها أو امرأة يتزوجها فهجرته إلى ما هاجر إليه

البخاري 2529صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Emancipation of slaves
Chapter
Error and forgetfulness in manumission, divorce, and similar matters, and there is no manumission except for the sake of Allah
Numbering
Darussalam 2529
Bukhari 2529