كتاب الإمارة
33  
The Book on Government
(18)
Chapter: It is recommended for the army to swear allegiance to the ruler when intending to fight, and an account of Bay'at Ar-Ridwan beneath the tree
(18)
باب اسْتِحْبَابِ مُبَايَعَةِ الإِمَامِ الْجَيْشَ عِنْدَ إِرَادَةِ الْقِتَالِ وَبَيَانِ بَيْعَةِ الرِّضْوَانِ تَحْتَ الشَّجَرَةِ
Sahih Muslim 1856 e

It has been narrated (through a different chain of transmitters) on the authority of Jabir who said:

We were one thousand and four hundred on the Day of Hudaibiya when the Prophet (ﷺ) said to us: Today you are the best people on the earth. And Jabir said: If I had the eyesight, I could show you the place of the tree.
حَدَّثَنَا سَعِيدُ بْنُ عَمْرٍو الأَشْعَثِيُّ، وَسُوَيْدُ بْنُ سَعِيدٍ، وَإِسْحَاقُ بْنُ إِبْرَاهِيمَ، وَأَحْمَدُ، بْنُ عَبْدَةَ - وَاللَّفْظُ لِسَعِيدٍ قَالَ سَعِيدٌ وَإِسْحَاقُ أَخْبَرَنَا وَقَالَ الآخَرَانِ، حَدَّثَنَا سُفْيَانُ، عَنْ عَمْرٍو، عَنْ جَابِرٍ، قَالَ كُنَّا يَوْمَ الْحُدَيْبِيَةِ أَلْفًا وَأَرْبَعَمِائَةٍ فَقَالَ لَنَا النَّبِيُّ صلى الله عليه وسلم ‏ "‏ أَنْتُمُ الْيَوْمَ خَيْرُ أَهْلِ الأَرْضِ ‏"‏ ‏.‏ وَقَالَ جَابِرٌ لَوْ كُنْتُ أُبْصِرُ لأَرَيْتُكُمْ مَوْضِعَ الشَّجَرَةِ.
Reference : Sahih Muslim 1856e
In-book reference : Book 33, Hadith 108
USC-MSA web (English) reference : Book 20, Hadith 4580
  (deprecated numbering scheme)