The hadith the collections open with
Placed first in Ṣaḥīḥ al-Bukhārī deliberately.
إِنَّمَا الأَعْمَالُ بِالنِّيَّاتِ وَإِنَّمَا لِكُلِّ امْرِئٍ مَا نَوَى فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ وَمَنْ كَانَتْ هِجْرَتُهُ لِدُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَتَزَوَّجُهَا فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ
Innama-l-aʿmālu bi-n-niyyāt, wa innamā li-kulli-mri'in mā nawā.
“Actions are only by intentions, and every person will have only what he intended.”
The full narration
‘Umar bin Al Khattab reported the Apostle of Allaah(ﷺ) as saying “Actions are to be judged only by intentions and a man will have only what he intended. When one’s emigration is to Allaah and His Apostle, his emigration is to Allaah and His Apostle but his emigration is to a worldly end at which he aims or to a woman whom he marries , his emigration is to that for which he emigrated
Source
Sunan Abī Dāwūd · 2201
- Al-Albani: Sahih
- Muhammad Muhyi Al-Din Abdul Hamid: Sahih
- Shuaib Al Arnaut: Sahih
- Zubair Ali Zai: Sahih Bukhari (1) Sahih Muslim (1907)