Language:
كتاب الأحكام
93  
Judgments (Ahkaam)
(43)
Chapter: How do the people give the Bai'a to the Imam
(43)
باب كَيْفَ يُبَايِعُ الإِمَامُ النَّاسَ
Sahih al-Bukhari 7201

Narrated Anas:

The Prophet (ﷺ) went out on a cold morning while the Muhajirin (emigrants) and the Ansar were digging the trench. The Prophet (ﷺ) then said, "O Allah! The real goodness is the goodness of the Here after, so please forgive the Ansar and the Muhajirin." They replied, "We are those who have given the Pledge of allegiance to Muhammad for to observe Jihad as long as we remain alive."

حَدَّثَنَا عَمْرُو بْنُ عَلِيٍّ، حَدَّثَنَا خَالِدُ بْنُ الْحَارِثِ، حَدَّثَنَا حُمَيْدٌ، عَنْ أَنَسٍ ـ رضى الله عنه ـ خَرَجَ النَّبِيُّ صلى الله عليه وسلم فِي غَدَاةٍ بَارِدَةٍ وَالْمُهَاجِرُونَ وَالأَنْصَارُ يَحْفِرُونَ الْخَنْدَقَ فَقَالَ ‏ "‏ اللَّهُمَّ إِنَّ الْخَيْرَ خَيْرُ الآخِرَهْ فَاغْفِرْ لِلأَنْصَارِ وَالْمُهَاجِرَهْ ‏"‏ فَأَجَابُوا نَحْنُ الَّذِينَ بَايَعُوا مُحَمَّدَا عَلَى الْجِهَادِ مَا بَقِينَا أَبَدَا
Reference : Sahih al-Bukhari 7201
In-book reference : Book 93, Hadith 61
USC-MSA web (English) reference : Vol. 9, Book 89, Hadith 308
  (deprecated numbering scheme)